MatMenu
Themat-menu is a floating panel containing list of menu items. It provides contextual commands with keyboard navigation, focus management, and screen reader support.
Basic Usage
API Reference
MatMenu
Selector:mat-menu
Inputs
| Name | Type | Default | Description |
|---|---|---|---|
xPosition | 'before' | 'after' | 'after' | Position of the menu in the X axis |
yPosition | 'above' | 'below' | 'below' | Position of the menu in the Y axis |
overlapTrigger | boolean | false | Whether the menu should overlap its trigger |
hasBackdrop | boolean | undefined | - | Whether the menu has a backdrop |
backdropClass | string | - | Class to be added to the backdrop element |
panelClass | string | - | Classes to be added to the overlay panel |
classList | string | - | Deprecated Use panelClass instead |
aria-label | string | - | Aria label for the menu panel |
aria-labelledby | string | - | Aria labelledby for the menu panel |
aria-describedby | string | - | Aria describedby for the menu panel |
Outputs
| Name | Type | Description |
|---|---|---|
closed | EventEmitter<MenuCloseReason> | Event emitted when the menu is closed |
close | EventEmitter<MenuCloseReason> | Deprecated Switch to closed instead |
Methods
| Method | Description |
|---|---|
focusFirstItem(origin?: FocusOrigin): void | Focus the first item in the menu |
resetActiveItem(): void | Resets the active item in the menu |
setPositionClasses(posX?: MenuPositionX, posY?: MenuPositionY): void | Adds classes based on position |
MatMenuTrigger
Directive:[matMenuTriggerFor]
Inputs
| Name | Type | Default | Description |
|---|---|---|---|
matMenuTriggerFor | MatMenuPanel | - | References the menu instance that the trigger is associated with |
matMenuTriggerData | any | - | Data to be passed along to any lazily-rendered content |
matMenuTriggerRestoreFocus | boolean | true | Whether focus should be restored when the menu is closed |
Outputs
| Name | Type | Description |
|---|---|---|
menuOpened | EventEmitter<void> | Event emitted when the associated menu is opened |
menuClosed | EventEmitter<void> | Event emitted when the associated menu is closed |
onMenuOpen | EventEmitter<void> | Deprecated Switch to menuOpened instead |
onMenuClose | EventEmitter<void> | Deprecated Switch to menuClosed instead |
Methods
| Method | Description |
|---|---|
openMenu(): void | Opens the menu |
closeMenu(): void | Closes the menu |
toggleMenu(): void | Toggles the menu between the open and closed states |
updatePosition(): void | Updates the position of the menu |
triggersSubmenu(): boolean | Whether the menu triggers a sub-menu or a top-level one |
Properties
| Property | Type | Description |
|---|---|---|
menuOpen | boolean | Whether the menu is open |
dir | 'ltr' | 'rtl' | The text direction of the containing app |
MatMenuItem
Selector:[mat-menu-item]
Inputs
| Name | Type | Default | Description |
|---|---|---|---|
role | 'menuitem' | 'menuitemradio' | 'menuitemcheckbox' | 'menuitem' | ARIA role for the menu item |
disabled | boolean | false | Whether the menu item is disabled |
disableRipple | boolean | false | Whether ripples are disabled on the menu item |
Methods
| Method | Description |
|---|---|
focus(origin?: FocusOrigin, options?: FocusOptions): void | Focuses the menu item |
getLabel(): string | Gets the label to be used when determining whether the option should be focused |
Examples
Nested Menu
Menu Position
Icons in Menu
Accessibility
Keyboard Interaction
DOWN_ARROW: Moves focus to the next menu itemUP_ARROW: Moves focus to the previous menu itemHOME: Moves focus to the first menu itemEND: Moves focus to the last menu itemENTER: Activates the focused menu itemSPACE: Activates the focused menu itemESCAPE: Closes the menuLEFT_ARROW: Closes sub-menu (for LTR languages)RIGHT_ARROW: Opens sub-menu (for LTR languages)
ARIA
The menu trigger hasrole="button", aria-haspopup="menu", aria-expanded, and aria-controls attributes. Each menu item has role="menuitem" by default, which can be customized via the role input.
Focus Management
- When opened via keyboard, focus is placed on the first menu item
- When opened via mouse, focus remains on the trigger
- When closed, focus is restored to the trigger by default (configurable via
matMenuTriggerRestoreFocus)