Base · Overlays
Command
A searchable list of commands and destinations, filtered as the user types.
Props
import { PackageIcon, PlusIcon, RouteIcon, SettingsIcon, UsersIcon } from "lucide-react"
import {
Command,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
CommandSeparator,
CommandShortcut,
} from "@/components/ui/command"
<Command className="border shadow-md">
<CommandInput placeholder="Search shipments, routes, actions…" />
<CommandList>
<CommandEmpty>No results found.</CommandEmpty>
<CommandGroup heading="Go to">
<CommandItem>
<PackageIcon />
Shipments
</CommandItem>
<CommandItem>
<RouteIcon />
Routes
</CommandItem>
<CommandItem>
<UsersIcon />
Drivers
</CommandItem>
</CommandGroup>
<CommandSeparator />
<CommandGroup heading="Actions">
<CommandItem>
<PlusIcon />
Create shipment
<CommandShortcut>⌘N</CommandShortcut>
</CommandItem>
<CommandItem>
<SettingsIcon />
Open settings
<CommandShortcut>⌘,</CommandShortcut>
</CommandItem>
</CommandGroup>
</CommandList>
</Command>Overview
Command pairs a search field with a ranked list of results. Use it inline as a filterable list, or inside CommandDialog as a command palette opened with a keyboard shortcut. It is built for the keyboard: type, arrow, Enter.
When to use
- As a global command palette (⌘K) for jumping to pages, records and actions.
- For a long list of actions or destinations that is faster to search than to scan.
- As the list inside a custom picker, such as a Combobox with grouped results.
When not to use
- For a short, fixed set of actions on one object: use a Dropdown menu.
- For choosing a form value from a list: use a Select or Combobox.
- As the only route to a feature. A palette is a shortcut; keep the feature reachable through navigation.
Anatomy
Input
The search field with a leading search icon.
List
The scrolling results area, up to 18rem tall.
Group
A set of results under a heading.
Item
One result. Can hold an icon and a trailing shortcut.
Empty
The message shown when nothing matches.
Separator
A line between groups.
Props
The contract every language implements. Names follow each language’s conventions (camelCase in React, snake_case in Rust).
| Prop | Type | Default | Description |
|---|---|---|---|
| placeholder | string | Search shipments, routes, actions… | Placeholder of the search field. Set on CommandInput. |
| heading | string | Go to | Heading of the first group. Set on CommandGroup. |
| emptyText | string | No results found. | Message shown when nothing matches. Passed as children of CommandEmpty. |
| loop | boolean | false | Whether the arrow keys wrap from the last item to the first. Set on Command. |
| shouldFilter | boolean | true | Turn off to filter the items yourself, for example with server-side search. |
| onSelect | function | – | Called with the item's value when it is chosen. Set on CommandItem. |
States
- Rest
- All items listed; the first one is selected.
- Filtered
- Only matching items remain, ranked by match quality. Empty groups are hidden.
- Item selected
- Muted background on the item that Enter will run. Follows the pointer and the arrow keys.
- Empty
- The empty message replaces the list.
Accessibility
Role: combobox
| Keys | Action |
|---|---|
| Arrow Down/Arrow Up | Moves the selection through the results while focus stays in the search field. |
| Home/End | Selects the first or last result. |
| Enter | Runs the selected item. |
| Alt+Arrow Down/Alt+Arrow Up | Jumps to the next or previous group. |
| Escape | Closes the palette when it is shown in a CommandDialog. |
- Focus never leaves the input; the selected item is exposed with aria-activedescendant.
- CommandDialog has a visually hidden title and description. Set them to describe your palette.
- The shortcut that opens a palette is yours to register. Show it in the interface so people can discover it.
Design tokens
Change any of these in Foundations and this component follows, in every language.
Platform notes
- HTML / JS
- Planned
- Not built in HTML / JS yet.
- React
- Stable
- Matches the contract with no platform differences.
- React Native
- Draft
- Items are passed as `groups`. CommandDialog is a full-screen search (a page sheet on iOS) on phones and a centred panel over a scrim on tablets and web, opened from a search button, since there is no global shortcut; Command is the same search as an inline panel.
- Swift (SwiftUI)
- Planned
- Not built in Swift yet.
- Godot
- Planned
- Not built in Godot yet.
- Vue
- Draft
- Usage snippet only; same props and behavior as the React component.
- Svelte
- Draft
- Usage snippet only; same props and behavior as the React component.
- Solid
- Draft
- Usage snippet only; same props and behavior as the React component.