Menu button
A button that opens a menu of actions.
Live example
Actions menu
<dui-menu>
<button type="button" popovertarget="row-actions">Actions</button>
<div id="row-actions" popover data-popover>
<button type="button">Edit</button>
<button type="button">Duplicate</button>
<button type="button">Archive</button>
<hr>
<button type="button">Delete</button>
</div>
</dui-menu>
<p role="status" id="menu-result"></p>
Links are not a menu
<button type="button" popovertarget="account-links">Account</button>
<div id="account-links" popover data-popover>
<nav aria-label="Account" data-nav>
<ul>
<li><a href="#links-title">Profile</a></li>
<li><a href="#links-title">Billing</a></li>
<li><a href="#links-title">Sign out</a></li>
</ul>
</nav>
</div>
Attributes
| Attribute or value | Where | Effect |
|---|---|---|
<dui-menu> | wraps the button and its popover | |
popovertarget="menu-id" | the <button> (native) | |
popover data-popover | the menu element | |
<button> or <a href> children | the actions; <hr> separates groups |
Added by the component: aria-haspopup, aria-expanded, role="menu", role="menuitem", tabindex="-1".
Keyboard
| Key | Action |
|---|---|
| Enter / Space / Down Arrow | on the button, opens the menu and focuses the first item |
| Up Arrow | on the button, opens the menu and focuses the last item |
| Down Arrow / Up Arrow | next or previous item, wrapping |
| Home / End | first or last item |
| A letter | next item whose label starts with it |
| Enter / Space | activates the item and closes the menu |
| Esc | closes the menu and returns focus to the button |
| Tab | closes the menu and moves on |
Accessibility
<dui-menu>adds the ARIA and arrow keys. Without JavaScript, every action is a Tab stop.- For links to other pages, use a disclosure:
role="menu"means arrow keys and no Tab stops (APG note).
Specifications
See also
- Molecules
- Source:
css/components/molecules/menu-button.css,examples/molecules/menu-button.html - Demos: Dashboard view (Plain HTML, React, Angular, Astro, Vue, Svelte); Account settings view (Plain HTML, React, Angular, Astro, Vue, Svelte); Orders view (Plain HTML, React, Angular, Astro, Vue, Svelte)
How other systems do it
For comparison only; these are not the standard this system follows.