Skip to content

[DropdownMenu] is it possible to detect when submenu is closed? #1003

Answered by benoitgrelard
misha-erm asked this question in Help
Discussion options

You must be logged in to vote

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:

<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>
        <Dropdown…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@misha-erm
Comment options

Answer selected by misha-erm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants