Menu
Menus display a list of choices on a temporary surface. They appear when users interact with a button, action, or other control.Basic Menu
A basic menu opens over the anchor element by default.Icon Menu
Menu with icons for each menu item.Selected Menu
Usevariant="selectedMenu" to highlight the selected item.
Max Height Menu
Limit menu height with scrolling.Context Menu
Right-click context menu.Complementary Projects
For more advanced use cases with nested menus, consider using material-ui-popup-state.Props
anchorEl
- Type:
HTMLElement | ((element: HTMLElement) => HTMLElement) | null - Description: An HTML element, or a function that returns one. It’s used to set the position of the menu
open
- Type:
boolean - Required: Yes
- Description: If
true, the component is shown
onClose
- Type:
(event: object, reason: string) => void - Description: Callback fired when the component requests to be closed. The
reasonparameter can be:"escapeKeyDown","backdropClick","tabKeyDown"
autoFocus
- Type:
boolean - Default:
true - Description: If
true, will focus the[role="menu"]if no focusable child is found
disableAutoFocusItem
- Type:
boolean - Default:
false - Description: When opening the menu will not focus the active item but the
[role="menu"]unlessautoFocusis also set tofalse
variant
- Type:
'menu' | 'selectedMenu' - Default:
'selectedMenu' - Description: The variant to use. Use
menuto prevent selected items from impacting the initial focus
transitionDuration
- Type:
'auto' | number | { appear?: number, enter?: number, exit?: number } - Default:
'auto' - Description: The length of the transition in ms, or ‘auto’
slots
- Type:
{ root?: React.ElementType, paper?: React.ElementType, list?: React.ElementType, transition?: React.ElementType, backdrop?: React.ElementType } - Description: The components used for each slot inside the menu
slotProps
- Type:
{ root?: object, paper?: object, list?: object, transition?: object, backdrop?: object } - Description: The props used for each slot inside the menu
sx
- Type:
SxProps<Theme> - Description: System prop for defining CSS styles
Accessibility
- The menu is automatically associated with the button using
aria-controlsandaria-haspopup - Use
aria-labelledbyon the MenuList to reference the button - The menu automatically manages focus and keyboard navigation
- Arrow keys navigate between menu items
- Escape closes the menu
- Tab key closes the menu and moves focus to the next focusable element