Command
Fast, composable command menu for React.
When to Use
Use Command when you need to:
- Provide a keyboard-first search interface for actions, pages, or settings
- Build a command palette (Cmd+K / Ctrl+K) for power-user navigation
- Create a filterable list of options grouped by category
- Offer searchable menus with keyboard shortcut hints
- Implement spotlight-style search that overlays the entire application
When Not to Use
- Simple select dropdowns - use Select instead
- Autocomplete with free-text input - use Combobox (which wraps Command in a Popover)
- Right-click context actions - use Context Menu
- Static navigation menus - use Dropdown Menu or Navigation Menu
Default
Full-featured command menu with groups, icons, keyboard shortcuts, and disabled items.
Dialog
Command menu rendered inside a dialog overlay, triggered by a keyboard shortcut.
Press ⌘J
Command Palette
Search for a command to run...
Simple
Minimal command menu without icons, suitable for basic text-only lists.
UX & Design Guidelines
Grouping & Organization
Use CommandGroup with descriptive heading props to organize items by category (e.g., "Suggestions", "Settings", "Recent"). Separate groups with CommandSeparator for clear visual boundaries. Limit groups to 5-8 items each to avoid overwhelming users.
Search & Filtering
The built-in fuzzy search filters items automatically. Always include a CommandEmpty component with a helpful "No results found" message. For custom filtering (e.g., async search), set shouldFilter={false} on the root Command and implement your own filter logic.
Responsive Behavior
On mobile, use the inline variant (without Dialog) since overlay command palettes are less discoverable on touch devices. When using CommandDialog, ensure the dialog content does not exceed viewport height by constraining CommandList with max-h-[300px] (the default).
Color & Contrast
The command menu uses bg-popover with text-popover-foreground for the container. Selected items highlight with bg-accent and text-accent-foreground. Group headings and shortcut text use text-muted-foreground for visual hierarchy without competing with item labels.
Accessibility
Keyboard Navigation
- Arrow Up / Arrow Down — Navigate between items
- Enter — Select the highlighted item
- Escape — Close the command dialog
- Cmd + K — Common shortcut to open the command palette
- Type-ahead filtering begins immediately as the user types in the search input
Screen Reader Support
- Built on
cmdkwhich providesrole="listbox"androle="option"semantics - Group headings are announced via
role="group"witharia-label - Selected state is conveyed via
aria-selected - Disabled items are announced with
aria-disabled
Focus Management
When CommandDialog opens, focus is automatically placed on the search input. Focus is trapped within the dialog overlay, preventing interaction with background content. On close, focus returns to the element that triggered the dialog. The inline Command variant does not trap focus.
Dialog Labeling
The CommandDialog accepts title and description props that render as visually hidden text (using sr-only) for screen readers. Always provide meaningful values for these props.
ARIA Attributes
{/* Command with accessible labels */}
<CommandDialog
open={open}
onOpenChange={setOpen}
title="Command Palette"
description="Search for a command to run..."
>
<CommandInput placeholder="Type a command or search..." />
<CommandList>
<CommandEmpty>No results found.</CommandEmpty>
<CommandGroup heading="Actions">
<CommandItem onSelect={() => handleAction("profile")}>
<User />
<span>Profile</span>
<CommandShortcut>⌘P</CommandShortcut>
</CommandItem>
<CommandItem disabled>
<Lock />
<span>Admin Panel</span>
</CommandItem>
</CommandGroup>
</CommandList>
</CommandDialog>Related Components
Combobox
Autocomplete input using Command inside a Popover for inline selection.
Dropdown Menu
Displays a menu of actions triggered by a button without search filtering.
Dialog
Modal overlay used by CommandDialog for focus-trapped command palettes.
Context Menu
Right-click triggered menu for contextual actions at the pointer position.
API Reference
The Command component is composed of multiple parts. Each sub-component accepts the following props in addition to standard HTML attributes.
Command
Root container with built-in fuzzy filtering.
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | — | Additional CSS classes applied to the root container. |
| childrenrequired | ReactNode | — | Command content including input, list, groups, and items. |
| filter | (value: string, search: string) => number | — | Custom filter function. Return 1 to keep, 0 to remove. |
| shouldFilter | boolean | true | When false, disables built-in filtering for custom logic. |
| value | string | — | Controlled value of the selected item. |
| onValueChange | (value: string) => void | — | Callback when the selected item value changes. |
CommandDialog
Command menu rendered inside a dialog overlay with focus trapping.
| Prop | Type | Default | Description |
|---|---|---|---|
| open | boolean | false | Whether the dialog is open. |
| onOpenChange | (open: boolean) => void | — | Callback fired when the dialog open state changes. |
| title | string | "Command Palette" | Accessible title for the dialog (visually hidden). |
| description | string | "Search for a command..." | Accessible description for the dialog (visually hidden). |
| showCloseButton | boolean | true | Whether to show the close button in the dialog. |
CommandInput
Search input with a built-in search icon and automatic filtering.
| Prop | Type | Default | Description |
|---|---|---|---|
| placeholder | string | — | Placeholder text displayed when the input is empty. |
| value | string | — | Controlled value of the search input. |
| onValueChange | (value: string) => void | — | Callback fired when the search input value changes. |
| className | string | — | Additional CSS classes applied to the input. |
CommandItem
Selectable option within a command list or group.
| Prop | Type | Default | Description |
|---|---|---|---|
| value | string | — | Value used for filtering and selection. Defaults to text content. |
| onSelect | (value: string) => void | — | Callback fired when the item is selected via click or Enter. |
| disabled | boolean | false | When true, prevents selection and reduces opacity. |
| className | string | — | Additional CSS classes applied to the item. |
CommandGroup
Groups related command items under a heading.
| Prop | Type | Default | Description |
|---|---|---|---|
| heading | string | — | Heading text displayed above the group of items. |
| className | string | — | Additional CSS classes applied to the group. |