Command
A searchable list of actions or options: command menus, pickers and quick switchers. Built on cmdk, with groups, shortcuts, disabled items and an empty state. CK-UI's own ⌘K docs search is built with it, and so is Combobox.
Use ↑ ↓ and Enter, or click an item.
Installation
Add Command to your project with the CK-UI CLI. It copies the source into your project, so the code is yours to change.
- Adds
Command.tsxto your CK-UI folder (src/components/ck-ui by default)- Installs
cmdkreact-iconsif your project does not have them yet
First time with CK-UI in this project? Run npx ck-ui-cli@latest init once before adding components. The installation guide explains what it sets up.
Manual installationInstall the packages and copy the files yourself.
Install the following dependencies
Run these commands in your terminal to install the required packages
Create or update your Command component
Copy this code to create your Command component
Test Your Component
- 1. Add the component to a test page
- 2. Check all props and variants work as expected
- 3. Verify responsive behavior
- 4. Test with different content/data
- 5. Ensure accessibility features work correctly
In a Popover
Compose Command with Popover (or Modal) for pickers and palettes. The search box gets focus when the popup opens.
Custom Filtering
Set shouldFilter={false} and render the items you want, for example results from a search request. Pass filter instead to keep built-in filtering with your own scoring.
Accessibility
Command.Inputis a combobox that controls the listbox (Command.List); it is named bylabelon Root. Focus stays in the input, andaria-activedescendantpoints at the highlighted option.- Arrow keys move the highlight, Home/End jump to the first/last item, Enter runs the highlighted item. Disabled items are skipped.
- Each
Command.Groupis a group named by itsheading.Command.Shortcutis decorative; put real shortcuts inaria-keyshortcutson the element that handles them. - The highlight uses the accent token in both themes and is not conveyed by color alone (aria-selected).
API Reference
Styled parts over cmdk; their other props are cmdk's. Import with import * as Command from "@/components/ui/Command".
Command.Root
| Prop | Type | Default | Description |
|---|---|---|---|
label | "string" | "undefined" | Accessible name of the search box and list. |
value / defaultValue / onValueChange | "string" | "first item" | The highlighted item's value. |
shouldFilter | "boolean" | "true" | Set false to filter yourself. |
filter | "(value, search, keywords) => number" | "fuzzy score" | Custom ranking (0 hides the item). |
loop | "boolean" | "false" | Wrap around at the ends. |
className | "string" | "undefined" | Additional classes, merged last. |
Command.Input
| Prop | Type | Default | Description |
|---|---|---|---|
value / onValueChange | "string" | "undefined" | Controlled search text. |
wrapperClassName | "string" | "undefined" | Classes for the row around the input. |
hideIcon | "boolean" | "false" | Hide the search icon. |
children | "ReactNode" | "undefined" | Rendered after the input (e.g. a keyboard hint). |
className | "string" | "undefined" | Classes for the input. |
Command.List
The scrollable listbox.
| Prop | Type | Default | Description |
|---|---|---|---|
className | "string" | "undefined" | Additional classes, merged last. |
Command.Empty
Shown when no item matches.
| Prop | Type | Default | Description |
|---|---|---|---|
className | "string" | "undefined" | Additional classes, merged last. |
Command.Group
| Prop | Type | Default | Description |
|---|---|---|---|
heading | "ReactNode" | "undefined" | Visible group title; names the group. |
className | "string" | "undefined" | Additional classes, merged last. |
Command.Item
| Prop | Type | Default | Description |
|---|---|---|---|
value | "string" | "text content" | Identity and search text. Make it unique. |
keywords | "string[]" | "undefined" | Extra search terms. |
onSelect | "(value: string) => void" | "undefined" | Runs on Enter or click. |
disabled | "boolean" | "false" | Skipped by the keyboard; cannot be selected. |
className | "string" | "undefined" | Additional classes, merged last. |
Command.Separator
| Prop | Type | Default | Description |
|---|---|---|---|
className | "string" | "undefined" | Additional classes, merged last. |
Command.Shortcut
Decorative shortcut hint at the end of an item.
| Prop | Type | Default | Description |
|---|---|---|---|
className | "string" | "undefined" | Additional classes, merged last. |
Command.Loading
Shown while you load async items.
| Prop | Type | Default | Description |
|---|---|---|---|
className | "string" | "undefined" | Additional classes, merged last. |