Command
Find and run an action by typing. Use Command inline or CommandDialog for a palette, with grouped results and keyboard navigation.
Preview
Usage
When to use
- Find and run actions from a searchable list, inline or in a dialog.
- Let users navigate to a destination by searching its name or keywords.
When not to use
- Pick a form value from a searchable list. Use Combobox.
- A short fixed menu with no search. Use DropdownMenu.
- Registering global shortcuts. Add the handler in your application.
Examples
Workspace actions
In a dialog
The parent owns the open state and the action handlers. Closing returns focus to the button.
Custom search words
Do and don't
Do
- Use short verb-led labels and organize related actions into groups.
- Provide textValue for a custom label and keywords for alternative names.
- Let the application register its own global shortcut and handle action side effects.
Don't
- Do not use Command to submit a form value; use Combobox.
- Do not use live remote search or nested command pages in this version.
- Do not present a shortcut hint for a shortcut the application does not implement.
Props
| Name | Type | Values | Default | Description |
|---|---|---|---|---|
| label required | string | - | - | Accessible name of the search input and results list. |
| placeholder | string | - | Search actions… | Visible hint in the search input. |
| emptyText | string | - | No results found. | Status shown when no command matches the query. |
| search | string | - | - | Controlled search text. The parent updates it through onSearchChange. |
| defaultSearch | string | - | Initial search text for an uncontrolled Command. | |
| onSearchChange | function | - | - | Called with the new search text whenever the user types. |
| loop | boolean | - | true | Wrap arrow navigation from the last enabled result to the first. |
| open | boolean | - | - | Controlled open state of CommandDialog. |
| defaultOpen | boolean | - | false | Initial open state of an uncontrolled CommandDialog. |
| onOpenChange | function | - | - | Called when CommandDialog opens or closes. |
| heading required | string | - | - | Visible and accessible heading of CommandGroup. |
| value required | string | - | - | Unique CommandItem identifier passed to onSelect. It is not a persisted form selection. |
| keywords | node | - | - | An array of additional search words on CommandItem. |
| leadingIcon | node | - | - | Decorative CommandItem icon. Use a regular 16px icon. |
| shortcut | node | - | - | CommandItem keyboard hint: text uses a small Kbd; a CommandShortcut, Kbd or KbdGroup node keeps its own formatting and accessible name. Does not register a shortcut. |
| disabled | boolean | - | false | A disabled CommandItem stays visible but cannot highlight or activate. |
| onSelect | function | - | - | CommandItem callback receiving its value. CommandDialog closes after activation. |
| textValue | string | - | - | Searchable label for CommandItem when children contain a custom node. |
| title required | string | - | - | CommandDialog uses the title prop to name its dialog. Required on CommandDialog, absent on inline Command. |
| description | string | - | - | CommandDialog uses the description prop for an optional accessible description. |
Anatomy
| Part | Description |
|---|---|
| root | An enabled command or a disabled result. |
| control | Search input with combobox semantics. |
| placeholder | Hint shown in the empty search input. |
| list | Scrollable result list. |
| icon | Decorative icon before a command label. |
| groupLabel | Visible heading of a result group. |
| separator | Decorative line between visible groups. |
| empty | Status text when no command matches. |
| shortcut | A compact keyboard hint at the end of the row. Plain text uses small Kbd; supplied key hints or key groups render directly without another keycap. |
| content | Inline raised panel containing its search field and results. |
Accessibility
Role: combobox
| Keys | Action |
|---|---|
| ArrowDown / ArrowUp | Move the highlight through enabled visible commands without leaving the search field. |
| Home / End | Highlight the first or last enabled visible command. |
| Enter | Activate the highlighted command once; never activate while composing text. |
| Escape | Close CommandDialog and restore focus to the opener. Inline Command leaves Escape to its owner. |
| Tab / Shift+Tab | Follow normal focus order inline; stay inside the dialog when modal. |
- label is required and names both the search field and listbox.
- aria-activedescendant references only an enabled mounted option. aria-selected follows the current highlight.
- Each CommandGroup is named by its heading. Disabled items are announced as disabled.
- CommandDialog requires title and focuses the search field on open. It resets uncontrolled search on close.
- Use unique item values and plain non-interactive content. Actions belong in onSelect; do not nest links or buttons inside an option.
Install
npx werewolf-ui add commandRun npx werewolf-ui init once in your app before adding components. Init sets up tokens, their CSS import and agent rules. Add installs this component and its dependencies while preserving your theme. See Installation for requirements and the alternative registry setup.