Command menu
vig-command-menu ng-template[vigCommandMenuItem]
import { CommandMenu, CommandMenuItemTemplate } from '@vigdx/ui/command-menu';Basic
[commands] : { id, label, run } plus an optional group , keywords , icon , shortcut (shown, not bound) and disabled . Matches on the label come first, then keyword matches. Open it with [(open)] or the shortcut ( mod+k by default).
The keyboard shortcut
shortcut takes a combination such as mod+k (⌘K on Apple platforms, Ctrl K elsewhere) or mod+shift+p; false turns it off. Every menu shares one document listener, added with the first and removed with the last. Combinations with Ctrl, ⌘ or Alt work while typing in a field; a plain key such as / does not. Pressing it again closes the menu. Name it on the button that opens the menu:
<button type="button" aria-haspopup="dialog" aria-keyshortcuts="Control+K Meta+K"
(click)="menuOpen.set(true)">Search <kbd aria-hidden="true">Ctrl K</kbd></button>
<vig-command-menu [(open)]="menuOpen" [commands]="commands()" />Server results and recent commands
search receives the query and an AbortSignal and returns the commands to add after the local matches. It runs once typing pauses ( searchDebounce , 250 ms) and the signal aborts when the query changes. recent lists ids of commands to show first while the field is empty; record them from (executed) .
Custom rows
vigCommandMenuItem template renders the inside of each row, with the command as let-command and let-active . The row itself, an option of the list, stays the kit's. size sets the width: sm , md or lg (default).
Customize
The width follows the dialog tokens (--container-dialog-sm, -md, -lg) and the corners --radius-dialog. For layout tweaks, select a part by scope and name, e.g. [data-scope="command-menu"][data-part="item"][data-state="active"]; the styling hooks below list them all.
The App shell recipe puts the menu together with a sidebar, a top bar and stored recent commands.
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="command-menu"][data-part="dialog"] { … }: 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="command-menu"]
| Part | Element | data-state |
|---|---|---|
dialog | <dialog> ; style the backdrop with ::backdrop . | open, closed |
search | — | |
input | role="combobox" field. | — |
list | role="listbox" . | — |
group | role="group" ; presentation for ungrouped ones). | — |
group-heading | — | |
item | role="option" row. | active, inactive |
item-icon | vig-icon of a command. | — |
item-label | — | |
item-shortcut | <kbd> of a command's shortcut . | — |
empty | emptyLabel ). | — |
loading | loadingLabel ). | — |
error | search failed ( errorLabel ). | — |
status | — |
| 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 native modal
<dialog>: the page behind is inert, focus starts in the field and returns to where it was on close. Escape and a backdrop click (closeOnBackdropClick) close it. - Follows the APG combobox pattern: the field is a
comboboxcontrolling alistboxof options grouped by heading. Focus stays in the field; Arrow Up and Down move the active option (aria-activedescendant), wrapping and skipping disabled ones, Home and End jump to the ends, Enter runs it. - While an input method editor composes text (Japanese, Chinese, Korean), Enter and the arrows belong to it, including Safari's late confirming Enter.
- The number of results is announced politely once typing pauses, from a live region inside the dialog; loading states are shown but not announced.
- Matching is locale-aware and ignores case and accents: in Turkish
istanbulfindsİstanbul. - Every text is a key of the typed
labelsinput (ariaLabel,inputAriaLabel,placeholder,emptyLabel,resultsAnnouncement…), over the locale defaults.
API
CommandMenu
vig-command-menuCommand palette (Cmd+K / Ctrl+K): a search field with combobox semantics
over a listbox of commands, in a native modal <dialog>, following the APG
combobox pattern. Typing filters commands (label first, then keywords,
locale-aware); Arrow keys move the active command, Enter runs it and
closes the menu, Escape closes it, and focus returns to where it was.
<vig-command-menu [commands]="commands" (executed)="remember($event)" />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 |
|---|---|---|---|
closeOnBackdropClick | boolean | true | Close when the backdrop is clicked. Escape always closes. |
commands | readonly CommandItem[] | [] | The commands, filtered as the user types. |
labels | Partial<CommandMenuLabels> | — | Texts of the field, list and status (i18n); locale defaults. |
loading | boolean | false | Shows the loading state, e.g. while |
open | boolean | false | Two-way: open from code with |
recent | readonly string[] | [] | Ids of recently run commands, shown first under the |
search | CommandSearch | undefined | undefined | Loads more commands for a non-empty query (e.g. from a server), shown
after the matching |
searchDebounce | number | 250 | Pause in typing (ms) before |
shortcut | CommandMenuShortcut | 'mod+k' | Page-wide key combination that toggles the menu; |
size | CommandMenuSize | 'lg' | — |
| Name | Payload | Description |
|---|---|---|
executed | CommandItem | A command was chosen (Enter or click) and has run: the menu closes
first, then |
openChange | boolean | Two-way: open from code with |
searchFailed | unknown |
|
Templates and directives
| Selector | Export | Description |
|---|---|---|
ng-template[vigCommandMenuItem] | CommandMenuItemTemplate | Custom content of each command row, replacing the icon, label and
shortcut. The row itself ( |