Command menu

A Cmd+K / Ctrl+K palette: a search field over a list of commands in a modal dialog. Typing filters the commands; Enter runs one. Use it to jump to any page and to reach actions without the mouse.

  • vig-command-menu
  • ng-template[vigCommandMenuItem]
Import
import { CommandMenu, CommandMenuItemTemplate } from '@vigdx/ui/command-menu';

Basic

Pass [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).

Last command: none
New invoice Ctrl I
New customer
Dashboard
Inbox
Export to CSV
Archive 2024

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:

HTML
<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) .

Recent: none
Settings
Reports

Custom rows

A 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"]

CommandMenu styling hooks
Part Element data-state
dialog The native <dialog> ; style the backdrop with ::backdrop . open, closed
search The row of the search icon and the field. —
input The role="combobox" field. —
list The role="listbox" . —
group A group of commands ( role="group" ; presentation for ungrouped ones). —
group-heading The heading of a named group. —
item A role="option" row. active, inactive
item-icon The vig-icon of a command. —
item-label The label of a command. —
item-shortcut The <kbd> of a command's shortcut . —
empty The text shown when nothing matches ( emptyLabel ). —
loading The loading text ( loadingLabel ). —
error The text shown when search failed ( errorLabel ). —
status The visually hidden live region. —
CommandMenu 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

  • 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 combobox controlling a listbox of 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 istanbul finds İstanbul.
  • Every text is a key of the typed labels input (ariaLabel, inputAriaLabel, placeholder, emptyLabel, resultsAnnouncement…), over the locale defaults.

API

CommandMenu

vig-command-menu component

Command 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.

Example :
<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

CommandMenu props
Name Type Default Description
closeOnBackdropClickbooleantrue

Close when the backdrop is clicked. Escape always closes.

commandsreadonly CommandItem[][]

The commands, filtered as the user types.

labelsPartial<CommandMenuLabels>—

Texts of the field, list and status (i18n); locale defaults.

loadingbooleanfalse

Shows the loading state, e.g. while commands load.

open model booleanfalse

Two-way: open from code with [(open)], or with the shortcut.

recentreadonly string[][]

Ids of recently run commands, shown first under the recentLabel heading while the field is empty. Keep the list in your app (see executed).

searchCommandSearch | undefinedundefined

Loads more commands for a non-empty query (e.g. from a server), shown after the matching commands. Called once typing pauses for searchDebounce ms; the signal aborts when the query changes.

searchDebouncenumber250

Pause in typing (ms) before search runs.

shortcutCommandMenuShortcut'mod+k'

Page-wide key combination that toggles the menu; false for none.

sizeCommandMenuSize'lg'
—

Templates and directives

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 (role="option") stays the kit's.

Example :
<ng-template vigCommandMenuItem let-command let-active="active">…</ng-template>

Are you sure?