[DropdownMenu] is it possible to detect when submenu is closed? #1003
-
Hello 👋🏻 There is a property onOpenChange on DropdownMenu.Root but how can I detect when submenu was opened/closed? Is there any way to do it? I have next scenario:
Thank you |
Beta Was this translation helpful? Give feedback.
Answered by
benoitgrelard
Nov 26, 2021
Replies: 1 comment 1 reply
-
Hi @MikeYermolayev, If you are using submenus, it means you end up with nested Here's an example: <DropdownMenu.Root onOpenChange={/** know if the root menu open/closes */}>
<DropdownMenu.Trigger>Menu</DropdownMenu.Trigger>
<DropdownMenu.Content>
<DropdownMenu.Item>Item 1</DropdownMenu.Item>
<DropdownMenu.Item>Item 2</DropdownMenu.Item>
<DropdownMenu.Root onOpenChange={/** know if this particular sub menu open/closes */}>
<DropdownMenu.TriggerItem>Item 3</DropdownMenu.TriggerItem>
<DropdownMenu.Content>
<DropdownMenu.Item>Item 3.1</DropdownMenu.Item>
<DropdownMenu.Item>Item 3.2</DropdownMenu.Item>
</DropdownMenu.Content>
</DropdownMenu.Root>
</DropdownMenu.Content>
</DropdownMenu.Root> I hope that helps! |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
misha-erm
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @MikeYermolayev,
If you are using submenus, it means you end up with nested
DropdownMenu.Root
's.So all you need to do is set an
onOpenChange
on the submenu root.Here's an example: