Skip to content
Klarhimmel UI

Command

3 results

Rooms
Guests
New booking
npx shadcn add @klarhimmel/command

Examples

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

command.tsx
import { Theme } from '@/components/klarhimmel/theme/style';
import { Command, CommandDialog } from '@/components/klarhimmel/ui/command';

export default function Example() {
  return (
    <Theme theme="brand">
      <CommandDialog
        open
        onOpenChange={() => {}}
        title="Command menu"
        aria-label="Commands"
        hotkey="k"
        onSelect={(value) => console.log(value)}
        groups={[{ heading: 'Go to', items: [{ value: 'rooms', label: 'Rooms' }, { value: 'guests', label: 'Guests' }] }]}
      />
    </Theme>
  );
}

Import

Import

import { Command, CommandDialog } from '@/components/klarhimmel/ui/command';
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

PropTypeDefaultDescription
Command.groupsCommandGroup[]requiredRequired. 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.placeholderstring'Type a command or search…'The box ('Type a command or search…') and the empty message ('No results'). Pass them translated.
Command.emptyTextstring'No results'Shown when nothing matches.
Command.aria-labelstringrequiredRequired: 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.querystring-
Command.onQueryChange(query: string) => void-
Command.autoFocusboolean-
Command.classNamestring-Extra classes, merged after the component's own.
CommandDialog.openbooleanrequired
CommandDialog.onOpenChange(open: boolean) => voidrequired
CommandDialog.titlestringrequiredRequired: names the dialog for assistive tech. Not shown.
CommandDialog.hotkeystring-A letter that opens and closes it with Cmd or Ctrl held: 'k'.
CommandDialog.classNamestring-Extra classes, merged after the component's own.
CommandDialog.aria-labelstringrequiredRequired: names the search box and the list.
CommandDialog.onSelect(value: string) => void-Called with the item's value on Enter or click.
CommandDialog.placeholderstring-The box ('Type a command or search…') and the empty message ('No results'). Pass them translated.
CommandDialog.emptyTextstring-Shown when nothing matches.
CommandDialog.groupsCommandGroup[]requiredRequired. 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

KeyDoes
Cmd or Ctrl + KOpens and closes the palette (hotkey)
TypeNarrows the list; every word must match
Down / UpMoves the highlight, wrapping; disabled items are skipped
EnterChooses the highlighted item
EscapeClears 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