Context menu
[vigContextMenu]
import { ContextMenu } from '@vigdx/ui/menu';Basic
vigContextMenu and the object they act on to vigContextMenuData ; each item's run receives it, typed. The menu opens at the pointer, flips and stays inside the viewport, and closing it returns focus to where it was.
Table rows
vig-table , run receives the row the menu opened on, by pointer or by Shift+F10 on a control in the row. Outside the rows, the browser's own menu shows. The compiler cannot tie the directive's data type to the table's row type, so type the items with the row type yourself, MenuItem<FileRow>[] .
| Name | Size | |
|---|---|---|
| report.pdf | 1.2 MB | |
| notes.txt | 4 KB | |
| photo.jpg | 3.4 MB |
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
- A context menu is a shortcut that many users never find: keep its actions available elsewhere too, for example in a row's actions menu.
- Shift+F10 and the ContextMenu key open it at the focused element with the first item focused. A right-click focuses the menu itself, where the arrow keys start. The menu is a
role="menu"named byvigContextMenuLabels.ariaLabel(“Context menu” by default). - Inside, it works as the Menu: arrow keys, typeahead, submenus mirrored in right-to-left pages, checkbox and radio items. Escape and activating an item close it and return focus to the element that had it; Tab closes it too.
- It listens on its own element only. Where it has no items (an empty list, or a table's header) the browser's own menu shows; a nested
[vigContextMenu]wins over an outer one.
API
ContextMenu
[vigContextMenu]Opens a menu at the pointer on right-click (contextmenu), and at the
focused element on Shift+F10 or the ContextMenu key. Its items are the
same as vig-menu's, with submenus, groups and checkable items; run
receives vigContextMenuData. On a vig-table, run receives the row
the menu opened on, and the page's own menu shows outside the rows.
Closing returns focus to where it was. Listens on its own host only.
On a table, T is not tied to the table's row type by the compiler (a
directive cannot read its host component's type parameter): type the
items with the table's row type, MenuItem<Row>[], and they match.
A context menu is a shortcut: keep its actions reachable elsewhere too,
e.g. in a row's vig-menu.
<vig-table [items]="files" [vigContextMenu]="fileActions">…</vig-table>
<li [vigContextMenu]="actions" [vigContextMenuData]="file">…</li>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).
panel item icon label shortcut indicator submenu-indicator separator group group-heading
menu
open closed checked unchecked
data-opening data-closing
| Name | Type | Default | Description |
|---|---|---|---|
vigContextMenu | readonly (MenuItem<T> | 'separator')[] | [] | The menu's entries; empty opens nothing (the page's own menu shows). |
vigContextMenuData | T | — | Passed to each item's |
vigContextMenuLabels | Partial<ContextMenuLabels> | — | Texts of the menu (i18n); locale defaults. |
| Name | Payload | Description |
|---|---|---|
vigContextMenuCheckedChange | MenuCheckedChange<T> | A checkbox or radio item was activated: update its |
vigContextMenuSelected | MenuItem<T> | Emitted when an item is activated (its |
| Signature | Description |
|---|---|
close(): void | Closes the menu; focus returns to where it was before it opened. |