Command
3 results
Go to
Rooms
Guests
Actions
New booking
npx shadcn add @klarhimmel/commandCopy for AIExamples
Palette
Inline
Empty
DetailsAbout, usage, props and more
A search box over a list of actions, and the Cmd+K palette that puts it in a dialog.
When to use
Use for
A fast way to go anywhere or do anything by typing its name: the Cmd+K palette.
Not for
Choosing one value in a form. Use Combobox. Navigation people need to see. Use Tabs or a menu.
Pairs with
Dialog, Kbd, Button.
Preview
Press Ctrl or Cmd and K, or the button.
Import
Import
- Files
- command.tsx, in components/klarhimmel/ui/. With it: kbd, theme, utils. npm: lucide-react, radix-ui.
- Render in
- Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.
- Limit
- Overlays render into the Theme root with position: fixed. A transform on an ancestor re-parents fixed (a dialog centres in the wrapper) and overflow: hidden clips menus. Render <Theme> at the app root, outside any transformed wrapper.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
Command.groups | CommandGroup[] | required | Required. A group is { heading?, items }; an item is { value, label, keywords?, shortcut?, icon?, disabled? }. Every word typed must match a label or a keyword. Shortcuts only remind; the app binds the keys. |
Command.onSelect | (value: string) => void | - | Called with the item's value on Enter or click. |
Command.placeholder | string | 'Type a command or search…' | The box ('Type a command or search…') and the empty message ('No results'). Pass them translated. |
Command.emptyText | string | 'No results' | Shown when nothing matches. |
Command.aria-label | string | required | Required: names the search box and the list. |
Command.resultsLabel | (count: number) => string | (n) => `${n} ${n === 1 ? 'result' :… | What is announced as you type: default "3 results". Pass it translated. |
Command.query | string | - | |
Command.onQueryChange | (query: string) => void | - | |
Command.autoFocus | boolean | - | |
Command.className | string | - | Extra classes, merged after the component's own. |
CommandDialog.open | boolean | required | |
CommandDialog.onOpenChange | (open: boolean) => void | required | |
CommandDialog.title | string | required | Required: names the dialog for assistive tech. Not shown. |
CommandDialog.hotkey | string | - | A letter that opens and closes it with Cmd or Ctrl held: 'k'. |
CommandDialog.className | string | - | Extra classes, merged after the component's own. |
CommandDialog.aria-label | string | required | Required: names the search box and the list. |
CommandDialog.onSelect | (value: string) => void | - | Called with the item's value on Enter or click. |
CommandDialog.placeholder | string | - | The box ('Type a command or search…') and the empty message ('No results'). Pass them translated. |
CommandDialog.emptyText | string | - | Shown when nothing matches. |
CommandDialog.groups | CommandGroup[] | required | Required. A group is { heading?, items }; an item is { value, label, keywords?, shortcut?, icon?, disabled? }. Every word typed must match a label or a keyword. Shortcuts only remind; the app binds the keys. |
CommandDialog.resultsLabel | (count: number) => string | - | What is announced as you type: default "3 results". Pass it translated. |
Accessibility
| Key | Does |
|---|---|
Cmd or Ctrl + K | Opens and closes the palette (hotkey) |
Type | Narrows the list; every word must match |
Down / Up | Moves the highlight, wrapping; disabled items are skipped |
Enter | Chooses the highlighted item |
Escape | Clears the text; again, closes the dialog |
The WAI-ARIA combobox with an always-open listbox: focus stays in the box and aria-activedescendant follows the highlight. The number of results is announced as you type.
Accessibility