Command
A searchable list of actions, for command palettes and quick navigation.
When to use
- A command palette: search every action and page from one input, often opened with ⌘K.
- A searchable list of actions inside a panel or a popover.
When not to use
- Picking a value in a form field: use Combobox.
- A few actions on one object: use Dropdown Menu.
- Filtering the rows of a table: use Data Table.
Install
npx shadcn@latest add @clinia/commandAnatomy
- 1Container
data-slot="command"bg-popover · rounded-lg - 2Search input
data-slot="command-input"text-sm · border-input - 3Item
data-slot="command-item"text-sm · font-medium - 4Shortcut
data-slot="command-shortcut"text-xs · text-muted-foreground
Clinia rules
- Group items under short headings (
Go to,Settings). Headings aretext-xs text-muted-foreground. - Item labels start with a verb or name the destination:
Create API key,Sources. CommandEmptysays what didn't match:No sources match your search.- The search field is an Input Group, so it shares the
inputboundary with every other field. - In
CommandDialog, passtitleanddescriptionin sentence case. The palette shows no visible title, so screen readers rely on them.
Do and don't
States
no results
Toggle the site theme to review both themes.
Accessibility
Built in
- The input is a
comboboxthat controls alistboxof options. Focus stays in the input while Arrow Up and Arrow Down move the selection, and Enter runs the selected item. CommandDialogrenders a Dialog with a visually hidden title and description.
Your responsibility
- Pass
labeltoCommand. It becomes the input's visually hidden label. - Only show a
CommandShortcutfor a shortcut your app actually registers. - Keep disabled items rare, and say why in the label:
Billing (admins only).
How to test
- Focus the input and type: the list filters as you type.
- Press Arrow Down and Arrow Up: the selection moves. Press Enter: the selected item runs.
- Type something that matches nothing: the empty message shows.
- With a screen reader, the input is announced as a combobox, and each option is read as the selection moves.
API
CommandDialog
| Prop | Values | Default | Description |
|---|---|---|---|
| title | string | Command palette | Read by screen readers: the dialog has no visible title. |
| description | string | Search for a command to run… | Read by screen readers alongside the title. |
| showCloseButton | boolean | false | Shows the close button in the dialog's top corner. Off by default. |
All other props come from cmdk.