Menu

A list of actions that opens from a button. Use it for commands, like editing or sharing something. To pick a value for a form, use Select or Combobox.

General

Pass the element that opens the menu in trigger. A shortcut is shown next to the item.

Labels and dividers

Group the items with Menu.Label and separate the groups with Menu.Divider.

Menu.Sub opens a menu next to its item on hover, on click or with the right arrow. Submenus can be nested.

Checkbox and radio items

Menu.CheckboxItem turns an option on or off. Menu.RadioItem picks one value of its Menu.RadioGroup. Both keep the menu open.

Controlled

Control when the menu is open with visible and onVisibleChange.

APIs

Menu.Props

AttributeDescriptionTypeAccepted valuesDefault
triggerthe element that opens the menu, usually a ButtonReactElement--
visibleopen state, to control the menuboolean--
initialVisibleopen state at the startboolean-false
onVisibleChangecalled when the menu wants to open or close(visible: boolean) => void--
getPopupContainerelement that receives the menu, document.body when missing() => HTMLElement--
...native props, passed to the element around the triggerHTMLAttributes'id', 'className', ...-

Menu.Item.Props

AttributeDescriptionTypeAccepted valuesDefault
onClickcalled when the item is chosen, by click or key(event) => void--
iconshown before the labelReactNode--
shortcutshown after the label, only for the eyestring--
typecolor of the itemstring'default', 'error'default
disabledthe item cannot be chosen or focusedboolean-false
disableAutoClosekeep the menu open after the item is chosenboolean-false
...native propsHTMLAttributes'aria-keyshortcuts', ...-

Menu.CheckboxItem.Props

Accepts the props of Menu.Item, except onClick, plus:

AttributeDescriptionTypeAccepted valuesDefault
checkedwhether the option is onboolean-false
onChangecalled with the new state(checked: boolean) => void--
disableAutoClosekeep the menu open after the item is chosenboolean-true

Menu.RadioGroup.Props

AttributeDescriptionTypeAccepted valuesDefault
valuethe value of the checked itemstring--
onChangecalled with the value of the chosen item(value: string) => void--
...native props, name the group with aria-labelHTMLAttributes'aria-label', ...-

Menu.RadioItem.Props

Accepts the props of Menu.Item, except onClick, plus:

AttributeDescriptionTypeAccepted valuesDefault
valuethe value this item checks in its groupstring--
disableAutoClosekeep the menu open after the item is chosenboolean-true

Menu.Sub.Props

AttributeDescriptionTypeAccepted valuesDefault
labeltext of the item that opens itReactNode--
iconshown before the labelReactNode--
disabledthe submenu cannot be openedboolean-false
...native props, passed to the itemHTMLAttributes--

Menu.Label and Menu.Divider

Both accept native props. Menu.Label is a title for the items below it, and Menu.Divider is a line between groups.

Ref

The ref of Menu points at the element around the trigger. The ref of each item, of Menu.Label and of Menu.Divider points at its own element, and the ref of Menu.Sub at the item that opens it.

Accessibility

The trigger gets aria-haspopup="menu" and aria-expanded. The list is a menu, named by the trigger, with menuitem, menuitemcheckbox and menuitemradio items. A radio group is a group; name it with aria-label. The shortcut is only visual: to announce it, pass aria-keyshortcuts, like aria-keyshortcuts="Meta+E".

KeyAction
Arrow Down and UpOn the trigger, open on the first or the last item. In the menu, move between the items
Enter and SpaceChoose the focused item, or open its submenu
Home and EndGo to the first or the last item
Arrow RightOpen the submenu of the focused item
Arrow LeftClose the submenu and go back to its item
EscapeClose the submenu, or the menu and focus the trigger
TabClose the menu and focus the trigger
LettersGo to the next item that starts with what was typed

Disabled items are skipped by the keyboard.

Edit this page on GitHub