Menu
Combine a list of secondary actions into single interactive area
Source
LLM docs
Docs
PackageIcon
Usage
Submenus
Controlled
The dropdown's opened state can be controlled with the opened and onChange props:
Show menu on hover
Set trigger="hover" to reveal the dropdown when hovering over the menu target and dropdown.
The closeDelay and openDelay props can be used to control open and close delay in ms.
Note that:
- If you set
closeDelay={0}then the menu will close before the user reaches the dropdown, so setoffset={0}to remove space between the target element and dropdown. - Menu with
trigger="hover"is not accessible – users that navigate with the keyboard will not be able to use it. If you need both hover and click triggers, usetrigger="click-hover".
To make a Menu that is revealed on hover accessible on all devices, use trigger="click-hover" instead.
The dropdown will be revealed on hover on desktop and on click on mobile devices.
Disabled items
Dropdown position
Transitions
The Menu dropdown can be animated with any of the premade transitions from the Transition component:
Custom component as Menu.Item
By default, Menu.Item renders as a button element. To change that, set the component prop:
Note that the component you pass to the component prop should allow spreading props to its root element:
Custom component as target
Styles API
Menu supports the Styles API; you can add styles to any inner element of the component with the classNames prop. Follow the Styles API documentation to learn more.
Component Styles API
Hover over selectors to highlight corresponding elements
Menu.Target children
Menu.Target requires an element or a component as a single child – strings, fragments, numbers, and multiple elements/components are not supported and will throw an error. Custom components must provide a prop to get the root element ref; all Mantine components support ref out of the box.
Required ref prop
Custom components that are rendered inside Menu.Target are required to support the ref prop:
Pass ref to the root element:
Accessibility
Menu follows WAI-ARIA recommendations:
- Dropdown element has
role="menu"andaria-labelledby="target-id"attributes - Target element has
aria-haspopup="menu",aria-expanded,aria-controls="dropdown-id"attributes - Menu item has
role="menuitem"attribute
Whilst the dropdown is unopened, the aria-controls attribute will be undefined
Supported target elements
An uncontrolled Menu with trigger="click" (default) will be accessible only when used with a button element or component that renders it (Button, ActionIcon, etc.).
Other elements will not support Space and Enter key presses.
Hover menu
Menu with trigger="hover" is not accessible – it cannot be accessed with the keyboard. Use it only if you do not care about accessibility. If you need both hover and click triggers, use trigger="click-hover".
Navigation
If you are using the Menu to build navigation, you can use the options from the demo below to follow the WAI-ARIA recommendations for navigation.
Keyboard interactions
If you also need to support Tab and Shift + Tab then set menuItemTabIndex={0}.