Menu

Menu is a component that displays a common dropdown menu.

Usage

import { Menu } from "@yamada-ui/react"
<Menu.Root>
  <Menu.Trigger />
  <Menu.ContextTrigger />
  <Menu.Anchor />
  <Menu.Content>
    <Menu.Header />
    <Menu.Group>
      <Menu.Item>
        <Menu.Label />
        <Menu.Indicator />
        <Menu.Command />
      </Menu.Item>
    </Menu.Group>
    <Menu.Separator />
    <Menu.OptionGroup>
      <Menu.OptionItem />
    </Menu.OptionGroup>
    <Menu.Footer />
  </Menu.Content>
</Menu.Root>

Use Items

Change Size

Handle Selection Event

To handle selection event, use onSelect.

Add Dividers

Grouping

Display Icons

Display Commands

Set Selectable Items

Nested Menu

Use Context Menu

Display Menu on Different Element

Here display Popover

Disable Close on Select

To disable the close on select, set closeOnSelect to false.

Set Initial Focus

To set initial focus, pass a Ref to initialFocusRef.

Change Placement

To change the display position, set placement to "start", "end-end", etc. By default, "end-start" is set.

Change Animation

To change the animation, set animationScheme to "inline-start", "block-end", etc. By default, "scale" is set.

Change Offset

To change the offset, set a value to gutter or offset.

Change Duration

To change the duration, set a numerical value (seconds) to duration.

Access Internal State

To access internal state, pass a function to the children of Menu.Root.

Disable Close on Outside Click

To disable closing when clicking outside, set closeOnBlur to false.

Disabling Items

To disable items, set disabled to true.

To add header or footer, set ReactNode to header or footer of Menu.Content.

Control

Props

Accessibility

The Menu follows the WAI-ARIA - Menu and Menubar Pattern and WAI-ARIA - Menu Button Pattern for accessibility.

Keyboard Navigation

KeyDescriptionState
Space, EnterOpens the menu and focuses the first enabled item.-
Activates the focused item and closes all menus if already within the menu.closeOnSelect={true}
ArrowRightIf the focused item is a submenu trigger, opens the submenu and focuses the first enabled item.subMenuDirection="end"
Closes the submenu and focuses the submenu trigger if already within a submenu.subMenuDirection="start"
ArrowLeftIf the focused item is a submenu trigger, opens the submenu and focuses the first enabled item.subMenuDirection="start"
Closes the submenu and focuses the submenu trigger if already within a submenu.subMenuDirection="end"
ArrowUpOpens the menu and focuses the last enabled item. Focuses the previous enabled item if already within the menu. If on the first item, focuses the last.-
ArrowDownOpens the menu and focuses the first enabled item. Focuses the next enabled item if already within the menu. If on the last item, focuses the first.-
HomeFocuses the first enabled item if already within the menu.-
EndFocuses the last enabled item if already within the menu.-
EscapeCloses the menu and focuses the trigger.closeOnEsc={true}

ARIA Roles and Attributes

ComponentRoles and AttributesUsage
Menu.Triggerrole="button"Indicates that it is a button.
aria-controlsSet to the related Menu.Content id when the menu is open, undefined when closed.
aria-disabledSet to "true" when disabled is set.
aria-expandedSet to "true" when the menu is open, "false" when closed.
aria-haspopup="menu"Indicates that a menu exists.
Menu.ContextTriggerrole="application"Indicates that it is an application.
aria-controlsSet to the related Menu.Content id when the menu is open, undefined when closed.
aria-disabledSet to "true" when disabled is set.
aria-expandedSet to "true" when the menu is open, "false" when closed.
aria-haspopup="menu"Indicates that a menu exists.
Menu.Contentrole="menu"Indicates that it is a menu.
aria-activedescendantSet to the id of the focused item.
aria-hiddenSet to "false" when the menu is open, "true" when closed.
aria-labelledbySet to the id of the related Menu.Trigger or Menu.ContextTrigger.
Menu.Labelrole="presentation"Indicates that it is for presentation.
Menu.Grouprole="group"Indicates that it is a group.
aria-labelledbySet to the id of the related Menu.Label.
Menu.Itemrole="menuitem"Indicates that it is a menu item.
aria-disabledSet to "true" when disabled is set.
Menu.OptionItemroleSet to "menuitemradio" when Menu.OptionGroup type is "radio", set to "menuitemcheckbox" when type is "checkbox".
Menu.Separatorrole="separator"Indicates that it is a separator.