Menu
Combine a list of secondary actions into single interactive area
Import
Source
Docs
Package
Usage
Controlled
Dropdown opened state can be controlled with opened
and onChange
props:
Show menu on hover
Set trigger="hover"
to reveal dropdown when hovers over menu target and dropdown.
closeDelay
and openDelay
props can be used to control open and close delay in ms.
Note that:
- If you set
closeDelay={0}
then menu will close before user will reach dropdown, setoffset={0}
to remove space between target element and dropdown. - Menu with
trigger="hover"
is not accessible – users that navigate with keyboard will not be able to use it. If you need click-hover hover and click triggers, usetrigger="click-hover"
.
To make 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
Menu dropdown can be animated with any of premade transitions from Transition component:
Custom component as Menu.Item
By default, Menu.Item
renders as button element, to change that set component
prop:
Note that the component you pass to component
prop should allow spreading props to its root element:
Custom component as target
Styles API
Menu
supports Styles API, you can add styles to any inner element of the component withclassNames
prop. Follow 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 error. Custom components must provide a prop to get 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 ref
prop:
Use forwardRef
function to forward ref to 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
Supported target elements
Uncontrolled Menu with trigger="click"
(default) will be accessible only when used with 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 keyboard, use it only if you do not care about accessibility. If you need click-hover hover and click triggers, use trigger="click-hover"
.
Navigation
If you are using the Menu to build a Navigation, you can use the options from the demo below to follow the WAI-ARIA recommendations for navigation.
Keyboard interactions
Key | Description | Condition |
---|---|---|
Escape | Closes dropdown | Focus within dropdown |
Space/Enter | Opens/closes dropdown | Focus on target element |
ArrowUp | Moves focus to previous menu item | Focus within dropdown |
ArrowDown | Moves focus to next menu item | Focus within dropdown |
Home | Moves focus to first menu item | Focus within dropdown |
End | Moves focus to last menu item | Focus within dropdown |
If you also need to support Tab
and Shift + Tab
then set menuItemTabIndex={0}
.