Replies: 1 comment 5 replies
-
|
Moving this to a discussion as I can't reproduce this. CleanShot.2025-11-07.at.14.42.26.mp4import * as menu from '@zag-js/menu';
import { normalizeProps, useMachine } from '@zag-js/react';
import { useId } from 'react';
interface MenuProps {
open?: boolean;
setOpen?: (newOpen: boolean) => void;
}
export default function Menu(props: MenuProps) {
const { open, setOpen } = props;
const id = useId();
const service = useMachine(menu.machine, {
id,
open,
onOpenChange: (details) => {
setOpen?.(details.open);
},
});
const api = menu.connect(service, normalizeProps);
return (
<div>
<button {...api.getTriggerProps()}>
Actions <span {...api.getIndicatorProps()}>▾</span>
</button>
<div {...api.getPositionerProps()}>
<ul {...api.getContentProps()}>
<li {...api.getItemProps({ value: 'edit' })}>Edit</li>
<li {...api.getItemProps({ value: 'duplicate' })}>Duplicate</li>
<li {...api.getItemProps({ value: 'delete' })}>Delete</li>
<li {...api.getItemProps({ value: 'export' })}>Export...</li>
</ul>
</div>
</div>
);
}If you can still reproduce this, consider using onOpenChange: (details) => {
flushSync(()=>{
setOpen?.(details.open);
})
}, |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
🐛 Bug report
The menu unexpectedly closes after opening when toggling between two menus with at least one controlled menu. I'll let the videos below speak for themselves.
💥 Steps to reproduce
See reproduction and video below for more details.
💻 Link to reproduction
In the project, there's a const called
ENABLE_HACKSthat you can set totrueorfalse. The const will activate some hacks that fix this specific problem.StackBlitz reproduction: https://stackblitz.com/edit/zag-js-menu-interaction-problem?file=src%2FApp.tsx,src%2FMenu.tsx
🧐 Expected behavior
The menu shouldn't close after opening.
🧭 Possible Solution
I'm not exactly sure. I went through Zag's code base and was able to prevent the issue from happening by overriding the
focusTriggeractions of the menu machine and by preventing the default event on specific dismiss requests coming from the layer.Please let me know if there's anything I can do to help.
🌍 System information
📝 Additional information
The problem
Screen.Recording.2025-11-06.at.16.37.33.mov
With the hacks (no more problems)
Screen.Recording.2025-11-06.at.16.38.32.mov
Beta Was this translation helpful? Give feedback.
All reactions