Menu

A list of actions or links that opens from a trigger button, with submenus, headed groups and checkbox or radio items. Use it to tuck away secondary actions, such as row actions in a table or an overflow menu in a toolbar. The same items drive the menubar and the context menu.

  • vig-menu
  • [vigMenuTrigger]
  • ng-template[vigMenuItem]
Import
import { Menu, MenuTrigger, MenuItemTemplate } from '@vigdx/ui/menu';

Basic

Project a trigger marked vigMenuTrigger — a vig-button or a native button — and pass the entries as items . 'separator' draws a divider, danger styles destructive items, and selected emits the activated item.

Last action: none

An item with items opens a submenu to the inline end (the left in right-to-left pages), flipping at the viewport's edge. shortcut shows a key combination at the end of the row; it is display only. Activating any item closes every open menu.

Last action: none

Groups, checkbox and radio items

Consecutive items with the same group are listed under that heading. type: 'checkbox' or 'radio' with checked makes checkable items; your app owns the state, so update it from run (or the checkedChange output). Space toggles an item and keeps the menu open, Enter and a click toggle and close it.

Word wrap on, comfortable density

Row actions

An icon-only trigger per row, named with ariaLabel . Each item's run performs the action, with the row in scope. The panel opens below the trigger's end edge and flips when space runs out.

  • Website relaunch
  • Mobile app
  • Annual report

Items with an href render as links; target="_blank" adds rel="noopener noreferrer" . For router navigation, give the link a run that calls the router: a plain click goes to run , while Ctrl or Cmd and middle clicks still open the URL in a new tab. Separators group related entries, and disabled items stay visible but are skipped by the arrow keys.

Custom item template

An ng-template vigMenuItem replaces the icon and label of every item; let-item is the menu item. Here it adds keyboard shortcut hints.

What changed in 2.1

Existing menus look and behave a little differently since 2.1:

  • Panels fade in and out (with a small slide when motion is not reduced), in about 120 ms. While a menu closes, its panel stays in the page with data-closing until the exit ends; tests that expect it gone at once should wait for it.
  • Typing a letter moves to the next item that starts with it; a Space typed within such a search belongs to it ("save as"), otherwise Space activates the item when the key comes up.
  • A long menu is capped at the viewport's height and scrolls inside itself.
  • After a pointer activation, focus returns to the trigger without a focus ring.

Styling hooks

Internal elements carry a stable data-part and the component's data-scope; both are public API, so removing one is a breaking change. Select a part by both, e.g. [data-scope="menu"][data-part="panel"] { … }: the pair stays within this component when kit components nest, and also reaches parts in overlay panels, which render outside the host. State is exposed through aria-* and, where listed, a data-state; literal values are checked by the API gate, values computed from the component's state follow its documented types. Other data-* attributes listed below (such as data-opening while an overlay animates) are API too. See Customizing.

Scope: [data-scope="menu"]

Menu styling hooks
Part Element data-state
panel A role="menu" panel (also each submenu), in the overlay container. —
item A menu item, <a> or <button> : open / closed with a submenu, checked / unchecked when checkable. open, closed, checked, unchecked
icon The item icon. —
label The item text. —
indicator The check mark or radio dot of a checkable item. —
shortcut The <kbd> of an item's shortcut . —
submenu-indicator The chevron of an item that opens a submenu. —
group A role="group" of items sharing a group heading. —
group-heading The heading of a group. —
separator A separator <hr> . —
Menu data attributes
Attribute Meaning
data-opening On the overlay element (panel or <dialog> ) while its entrance transition plays; removed once it settles (2s at most). Style the entrance with data-opening: utilities.
data-closing On the overlay element while its exit transition plays, before it closes; removed once it settles (2s at most). Style the closed look with data-closing: utilities.

Accessibility

  • Follows the WAI-ARIA APG menu button pattern: the trigger gets aria-haspopup="menu", aria-expanded and aria-controls; the panel is a role="menu" labelled by the trigger, with role="menuitem" buttons or links.
  • Enter, Space or ArrowDown on the trigger opens the menu on the first item, ArrowUp on the last, and so do a touch tap and a screen reader's double-tap. A mouse click opens it without moving focus from the trigger, where the arrow keys then enter it. Inside, ArrowUp and ArrowDown wrap, Home and End jump, typing a letter moves to the next item starting with it, and disabled items are skipped. Keyboard focus shows an outline on the item, which forced-colors mode keeps.
  • Submenu items have aria-haspopup="menu" and aria-expanded. ArrowRight, Enter or Space opens a submenu on its first item; ArrowLeft and Escape close one level and return to its item; both arrows are mirrored in right-to-left pages. Hovering an item opens its submenu after a short delay, and while the pointer travels diagonally toward it, the items it crosses do not take over (a safe triangle).
  • Checkable items are menuitemcheckbox and menuitemradio with aria-checked; groups are role="group" named by their heading. Shortcuts are hidden from assistive technology: they work outside the menu, not in it.
  • Escape closes the menu and returns focus to the trigger. Tab closes every menu and continues from the trigger's place in the page (Shift+Tab lands on the trigger), even though menus render at the end of the page; a click outside closes them and lets focus move on. Activating an item closes every menu, so none stays open after navigation.
  • Separators are native <hr> elements, which menus expose as separators.
  • Icon-only triggers have no visible text: give them an ariaLabel that names the object, e.g. “Actions for Mobile app”.
  • Item icons are decorative. Keep custom vigMenuItem templates free of interactive elements; the item itself is the button or link.

API

Menu

vig-menu component

Action menu behind a trigger (PrimeNG popup p-menu and TieredMenu territory), following the APG menu-button pattern: opening moves focus into the menu (a mouse click leaves it on the trigger, where arrow keys enter), arrow keys wrap, typing jumps to an item, Escape returns to the trigger. Items may open submenus (items), sit in headed groups, and be checkbox or radio items; every menu closes once an item is activated.

Example :
<vig-menu [items]="actions" (selected)="run($event)">
  <vig-button vigMenuTrigger label="Actions" />
</vig-menu>

While it plays its entrance or exit transition, the animating element carries data-opening or data-closing (stable hooks for styling and for waiting in tests; see the theming guide). data-opening data-closing

Menu props
Name Type Default Description
itemsreadonly MenuEntry[][]
—

Templates and directives

Templates and directives
Selector Export Description
[vigMenuTrigger]MenuTrigger

Wires a projected element as the menu trigger. Works on a native button or on a component wrapping one (e.g. vig-button): the ARIA state lands on the actual interactive element.

ng-template[vigMenuItem]MenuItemTemplate

Custom rendering for the items of a vig-menu, replacing the default icon + label inside each role="menuitem" button.

Example :
<vig-menu [items]="actions">
  <vig-button vigMenuTrigger label="Actions" />
  <ng-template vigMenuItem let-item>
    <i [class]="item.icon" aria-hidden="true"></i> {{ item.label }}
  </ng-template>
</vig-menu>

Are you sure?