Menu
Material Design 3 menu surfaces for action lists and context commands. Not intended for multi-step workflows; use dialogs or sheets when users must review substantial content before acting.
Basic Usage
Open a simple anchored menu with text actions. Menus provide concise command lists tied to the current trigger context.
<ds-button id="menu-trigger-basic">Open Menu</ds-button> <ds-menu anchor="menu-trigger-basic"> <ds-menu-item>Profile</ds-menu-item> <ds-menu-item>Settings</ds-menu-item> <ds-menu-item divider></ds-menu-item> <ds-menu-item>Sign out</ds-menu-item> </ds-menu>
Initial Value
Use initial selected and disabled states to match current context.
<ds-menu anchor="menu-trigger-initial"> <ds-menu-item selected>Name</ds-menu-item> <ds-menu-item>Date modified</ds-menu-item> <ds-menu-item disabled>Size (Unavailable)</ds-menu-item> </ds-menu>
Variants
Use slot content patterns for icon-led and shortcut-style menus.
Leading Icons
Trailing Content
<ds-menu-item> <ds-icon slot="leading">content_copy</ds-icon> Copy <span slot="trailing">Ctrl+C</span> </ds-menu-item>
States
Menus support open/closed, selected, disabled, and divider states.
menu.open(); menu.close();
Interactive Example
Select an item to view emitted event details.
Event log:
API
Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
anchor |
string | null | ID of the element used for anchored positioning. |
open |
boolean | false | Reflects whether the menu is open. |
Events
| Event | Detail | Description |
|---|---|---|
ds-menu:open |
{} |
Fired when the menu opens. |
ds-menu:close |
{} |
Fired when the menu closes. |
ds-menu:select |
{ item } |
Fired when an enabled item is selected. |
Methods
| Method | Description |
|---|---|
open() |
Open the menu. |
close() |
Close the menu. |
toggle() |
Toggle between open and closed states. |
Menu Item Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
disabled |
boolean | false | Disables interaction for the item. |
selected |
boolean | false | Marks an item as selected. |
divider |
boolean | false | Renders a divider row. |
keep-open |
boolean | false | Keeps the menu open after click. |
CSS Custom Properties
| Property | Description |
|---|---|
--ds-menu-item-min-height |
Minimum menu item height (defaults to control-lg). |
--ds-menu-item-leading-size |
Leading icon slot size (defaults to icon-lg). |
--ds-menu-container-padding-block |
Menu panel top/bottom padding. |
Accessibility
Keyboard Interaction
| Key | Context | Expected Result |
|---|---|---|
Arrow Up / Arrow Down |
Menu open | Moves focus between enabled menu items |
Enter / Space |
Focus on menu item | Selects the focused item |
Escape |
Menu open | Closes the menu and returns focus to trigger |
Tab |
Menu open | Closes the menu and continues focus navigation |
Semantics
-
Menu surface uses
role="menu"; items userole="menuitem". - Disabled items expose
aria-disabled="true". - Backdrop click closes the menu for pointer users.
Usage Guidelines
- When to use: Use menus for compact, contextual command lists anchored to a trigger element.
- When not to use: Avoid menus for long explanations, multi-step tasks, or destructive flows requiring strong confirmation.
- Composition: Use concise labels, group related actions with dividers, and add leading icons only when they improve recognition.
-
Common mistakes: Overusing
keep-opencan confuse expected menu behavior. Reserve it for explicit multi-select interactions.