Chapter 03 Actions
Command palette
A search over the app's actions, in a dialog. Ctrl+K or ⌘K opens it from anywhere; typing filters, the arrow keys move and Enter runs. Screen readers hear how many commands match as you type. Keep a visible button for it too: a shortcut nobody knows about is no way in.
import { CommandPaletteComponent, type Command } from '@okaapi-ui/angular';
// Built on the kit's dialog. Add @angular/cdk/overlay-prebuilt.css.Commands
Press Ctrl+K (⌘K on a Mac) on this page, or the button. Try typing invoice: keywords find New order.
<button ui-button variant="secondary" (click)="open.set(true)">Commands</button>
<ui-command-palette [commands]="commands" [(open)]="open" (run)="go($event)" />
commands: Command[] = [
{ id: 'new', label: 'New order', keywords: ['invoice', 'bill'], shortcut: 'Ctrl N' },
{ id: 'find', label: 'Find a customer', keywords: ['search', 'client'] },
{ id: 'out', label: 'Sign out' },
];When to use something else
| If you need | Use |
|---|---|
| Pick a value inside a form | Combobox |
| Search the items of one list | Search field |
| A few actions on one thing | Menu |
Inputs
| Name | Type | Default | What it does |
|---|---|---|---|
commands | Command[] | — | Required. { id, label, keywords?, shortcut? }. Keywords find a command by other words; shortcut is only shown. |
shortcut | string | null | 'k' | The letter that opens it with Ctrl or ⌘. null turns it off. |
title | placeholder | string | 'Commands' from labels | Names the dialog and the field; text in the empty field. |
emptyLabel | closeLabel | string | — | Shown when nothing matches; the close button. Translate them. |
countLabel | (count: number) => string | `${n} commands` from labels | Announced as you type. Translate it. |
[(open)] | boolean | false | Open or closed; Ctrl+K and Escape change it. |
(run) | Command | — | The command to run, after the dialog has closed and focus is back. |
Keyboard and screen readers
| Keys | What they do |
|---|---|
| Ctrl + K or ⌘ + K | Open it from anywhere. |
| Up or Down | Move through the matching commands, wrapping round. |
| Enter | Run the highlighted command. |
| Escape | Close it. |
- How many commands match is announced as you type.
- Keep a visible button for it too: a shortcut nobody knows about is no way in.