Vastu

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

AttributePropertyTypeDefaultDescription
openopenbooleanfalseWhether the menu is open.
labellabelstring''The button's text, and the menu's accessible name.
variantvariant'secondary' | 'ghost''secondary'The button's look, as for va-button.
placementplacement'bottom-start' | 'bottom-end''bottom-start'Which edge of the button the menu lines up with.

Events

EventDescription
va-selectWhen the user chooses an item. event.detail.value is the item's value; event.detail.item is the item.

Slots

SlotDescription
(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 propertyTypeDescription
--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.
PartDescription
::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

KeyDoes
EnterOpens the menu and focuses the first item.
SpaceOpens the menu and focuses the first item.
ArrowDownOpens the menu and focuses the first item.
ArrowDownMoves to the next item, wrapping round.
ArrowUpMoves to the previous item, wrapping round.
HomeMoves to the first item.
EndMoves to the last item.
EnterChooses the focused item and closes the menu.
EscapeCloses 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.