Menu
vig-menu [vigMenuTrigger] ng-template[vigMenuItem]
import { Menu, MenuTrigger, MenuItemTemplate } from '@vigdx/ui/menu';Basic
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.
Submenus and shortcuts
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.
Groups, checkbox and radio items
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.
Row actions
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
Links, groups and disabled items
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
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-closinguntil 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"]
| Part | Element | data-state |
|---|---|---|
panel | role="menu" panel (also each submenu), in the overlay container. | — |
item | <a> or <button> : open / closed with a submenu, checked / unchecked when checkable. | open, closed, checked, unchecked |
icon | — | |
label | — | |
indicator | — | |
shortcut | <kbd> of an item's shortcut . | — |
submenu-indicator | — | |
group | role="group" of items sharing a group heading. | — |
group-heading | — | |
separator | <hr> . | — |
| Attribute | Meaning |
|---|---|
data-opening | <dialog> ) while its entrance transition plays; removed once it settles (2s at most). Style the entrance with data-opening: utilities. |
data-closing | data-closing: utilities. |
Accessibility
- Follows the WAI-ARIA APG menu button pattern: the trigger gets
aria-haspopup="menu",aria-expandedandaria-controls; the panel is arole="menu"labelled by the trigger, withrole="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"andaria-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
menuitemcheckboxandmenuitemradiowitharia-checked; groups arerole="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
ariaLabelthat names the object, e.g. “Actions for Mobile app”. - Item icons are decorative. Keep custom
vigMenuItemtemplates free of interactive elements; the item itself is the button or link.
API
Menu
vig-menuAction 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.
<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
| Name | Type | Default | Description |
|---|---|---|---|
items | readonly MenuEntry[] | [] | — |
| Name | Payload | Description |
|---|---|---|
checkedChange | MenuCheckedChange | A checkbox or radio item was activated: update its |
selected | MenuItem | Emitted when an item is activated (its |
| Signature | Description |
|---|---|
close(refocus = true): void | Closes the menu and its submenus. Focus returns to the trigger when
asked to, and always when it is still in a menu or was dropped from one
(scroll auto-close, a click on a blank area), so it never falls back to
|
onTriggerFocusOut(event: FocusEvent): void | Focus left a trigger whose menu a mouse opened, for somewhere other than the menu. |
onTriggerKeydown(event: KeyboardEvent): void | — |
onTriggerPointerDown(event: PointerEvent): void | Remembers which kind of pointer pressed the trigger. |
openMenu(fromEnd = false, enter = true): void | Opens the menu; |
toggle(event?: MouseEvent): void | Opens or closes the menu from a trigger click. Only a mouse click leaves focus on the trigger (no item is focused, the arrow keys enter). Every other open enters the menu: the keyboard (Enter or Space), touch, a pen, and a screen reader's double-tap, whose user could not otherwise reach a menu that renders at the end of the page. |
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 |