Skip to Content
Puzzle

Command

Searchable, keyboard-navigable command lists and command palettes.

Command provides a searchable list of actions. Use it inline for a compact action menu, or use CommandDialog to present the list as a modal command palette.

Import

import { Command, CommandDialog } from "@puzzle-ui/ui";

Inline command list

Pass commands as data. By default, search matches every query term against each command's label, description, keywords, and group, without case or accent sensitivity. Select an item with a click or the keyboard.

390 × 440

Command dialog

CommandDialog wraps the list in a modal dialog. It opens with ⌘K on macOS or Ctrl+K elsewhere by default, and closes after a command is selected. The shortcut is ignored while focus is in an editable field. Set shortcut={false} to disable it.

390 × 200

Visibility can be controlled with open and onOpenChange, or initialized with defaultOpen. When controlled, update open in response to onOpenChange.

Filtering and query state

Use query with onQueryChange to control the search input. defaultQuery sets its initial value when using the built-in state. Provide filter to replace the default matching behavior:

<Command
  commands={commands}
  query={query}
  onQueryChange={setQuery}
  filter={(command, search) => command.id.startsWith(search)}
/>

Use loading and loadingMessage while searching asynchronously. emptyMessage customizes the no-results message. Disabled items remain visible but cannot be selected or reached with keyboard navigation.

Keyboard interaction and accessibility

  • Arrow Up and Arrow Down move between enabled commands; navigation wraps by default. Set loop={false} to stop at the ends.
  • Enter selects the active command. Ctrl/Cmd+Home and Ctrl/Cmd+End move to the first and last enabled command.
  • autoFocus focuses the search input on mount and is enabled by default.
  • The search input is a labeled combobox associated with a listbox. Groups, disabled options, and result/loading status are exposed to assistive technology. Set label to provide a useful accessible name when the default is not appropriate.

API

Command

PropTypeDefaultDescription
commandsCommandItem[]RequiredItems to display.
placeholderstring"Search commands..."Search input placeholder.
labelstring"Search commands"Accessible name for the search input.
emptyMessageReactNode"No commands found."Message shown when there are no matching items.
loadingbooleanfalseShows the loading state instead of the list.
loadingMessageReactNode"Searching..."Loading and live-region message.
filter(command, query) => booleanDefault searchCustom matching function; replaces the default filter.
querystring-Controlled search query. Pair with onQueryChange.
defaultQuerystring""Initial query for an uncontrolled input.
onQueryChange(query: string) => void-Called when the search query changes.
onSelect(command: CommandItem) => void-Called when an enabled command is selected.
loopbooleantrueWhether keyboard navigation wraps at the ends.
autoFocusbooleantrueFocus the search input on mount.
classNamestring-Additional class on the root element.

Command also accepts standard div attributes, except children and onSelect.

CommandDialog

PropTypeDefaultDescription
openboolean-Controlled visibility.
defaultOpenbooleanfalseInitial visibility when uncontrolled.
onOpenChange(open: boolean) => void-Called when visibility changes are requested.
titleReactNode"Command palette"Dialog title.
descriptionstring-Optional dialog description.
shortcutstring | false"k"Key used with Ctrl/Cmd to toggle the dialog, or false to disable the shortcut.
commands, placeholder, label, emptyMessage, loading, loadingMessage, filter, onSelect, onQueryChange, query, defaultQuery, loop, classNameSame as CommandSame as CommandProps forwarded to the command list.

CommandItem

PropertyTypeDescription
idstringUnique item identifier, also used as its React key.
labelstringPrimary command text.
descriptionstringOptional secondary text; included in default search.
keywordsstring[]Optional extra search terms.
groupstringOptional group heading; included in default search.
shortcutstringOptional shortcut hint displayed with the item.
iconReactNodeOptional decorative icon.
disabledbooleanPrevents selection and keyboard focus.
onSelect() => voidOptional item-specific selection callback.

When selected, an item's onSelect runs before the component's onSelect. CommandDialog then requests that the dialog close.

;