Native Web Components playground

Nova v3.37.0

Preview

Web Components

Menu

nv-menu

A list of actions that opens from a trigger, such as an icon button, and closes after a choice.

Parts
Guides

Live demo

Placement

Use a menu to offer a short list of actions for a page or an item, opened from a button, icon button or avatar. Keep labels short and clear, group related actions, and avoid long menus. For choosing a form value, use a select or dropdown field instead.

Anatomy

A three-dot trigger above a menu of four items. Callouts mark 1 the trigger, 2 an item, 3 a leading icon, 4 a shortcut, 5 a submenu chevron and 6 a divider.

The parts of a menu.
  1. Trigger: any element in the trigger slot.
  2. Item (nv-menuitem): a label, with optional content in its default slot. A disabled item can't be chosen.
  3. Leading icon (icon).
  4. Shortcut (shortcut): text only; the menu doesn't register the keys.
  5. Submenu chevron (hasSubmenu): shown on the trigger item of a nested nv-menu.
  6. Divider: in the design only; Nova has no menu divider component. This example uses a standard HTML separator between the item groups.

Trigger and composition

The design offers button, icon-button and avatar triggers. In code, put a focusable element in the trigger slot and give icon-only triggers an accessible name. Other trigger content is possible if it supports the same interaction.

Figma provides item and divider partials for building a menu, and its menu slot can hold a custom arrangement. The code equivalent is a ul in the content slot containing nv-menuitem elements, with standard HTML separators between groups. There is no native menu-divider component. Alternatively, provide items to generate the menu from data. An item's default slot can replace its label content.

Look and feel

Items have resting, hover and disabled appearances. disabled removes an item from sequential keyboard focus and prevents selection. A shortcut label is a hint only: register the shortcut in the application. Use icons when they make an action easier to recognise, and keep related actions together without turning the menu into a long list.

Placement

placement accepts top, right, bottom or left, with optional -start or -end alignment; the default is bottom-start. The underlying popover adjusts its position when space is tight. Check placements near viewport edges, especially when a trigger moves in a responsive layout.

Behaviour

Choosing an item emits menuitemSelected with the item's name and closes the menu, unless disableCloseOnSelect is set. From a focused trigger, ArrowDown, Enter or Space opens the menu and focuses the first item. Arrow keys move between items, ArrowRight and ArrowLeft open and leave a submenu, and Escape closes the menu and returns focus to the trigger.

Sources