Menu <va-menu>
Opens a short list of actions from a button, such as Edit, Duplicate and Delete.
When to use it
- Use it
- For a few actions on one thing, when there isn't room to show them as buttons.
- Don't use it
- For navigation, for choosing a value in a form, or for one or two actions.
- Use instead
- Links for navigation; a select or radio group for form values; plain buttons for one or two actions.
Examples
Actions on an item
Items are buttons with a value. Choosing one fires va-select with that value.
<va-menu label="Actions">
<button value="edit">Edit</button>
<button value="duplicate">Duplicate</button>
<button value="move">Move to folder</button>
<button value="delete">Delete</button>
</va-menu>
Aligned to the end, ghost button
placement="bottom-end" lines the menu up with the button's right edge, for menus at the end of a row.
<va-menu label="More" variant="ghost" placement="bottom-end">
<button value="share">Share</button>
<button value="download">Download</button>
<button value="report">Report a problem</button>
</va-menu>
Install and import
npm install @firstprateek/vastu @firstprateek/vastu-tokens
import '@firstprateek/vastu-tokens/lekha.css'; // once per page
import '@firstprateek/vastu/menu';
API
Attributes and properties
| Attribute | Property | Type | Default | Description |
|---|
open | open | boolean | false | Whether the menu is open. |
label | label | string | '' | The button's text, and the menu's accessible name. |
variant | variant | 'secondary' | 'ghost' | 'secondary' | The button's look, as for va-button. |
placement | placement | 'bottom-start' | 'bottom-end' | 'bottom-start' | Which edge of the button the menu lines up with. |
Events
| Event | Description |
|---|
va-select | When the user chooses an item. event.detail.value is the item's value; event.detail.item is the item. |
Slots
| Slot | Description |
|---|
| (default) | The menu items, as <button value="…"> elements. |
Styling
Components read the brand's tokens. To adjust one component, set its custom properties or style its parts.
| Custom property | Type | Description |
|---|
--va-menu-bg | <color> | Background colour of the menu. |
--va-menu-radius | <length> | Corner radius of the menu. |
--va-menu-item-hover | <color> | Background colour of the focused or hovered item. |
| Part | Description |
|---|
::part(trigger) | The button that opens the menu. |
::part(menu) | The popup list. |
Accessibility
- Role
menu- Accessible name
- The
label, which is also the button's text. - Note
- The button has
aria-haspopup="menu" and aria-expanded. Items get role="menuitem". - Note
- Typing a letter moves to the next item that starts with it.
Keyboard
| Key | Does |
|---|
| Enter | Opens the menu and focuses the first item. |
| Space | Opens the menu and focuses the first item. |
| ArrowDown | Opens the menu and focuses the first item. |
| ArrowDown | Moves to the next item, wrapping round. |
| ArrowUp | Moves to the previous item, wrapping round. |
| Home | Moves to the first item. |
| End | Moves to the last item. |
| Enter | Chooses the focused item and closes the menu. |
| Escape | Closes the menu and returns focus to the button. |
Every row on this page is checked by contract tests generated from the same manifest, in Chromium, Firefox and WebKit. Read the manifest.