Skip to main content

Command

StorybookView in Storybook

Explore interactive examples and all component variations in our Storybook.

The Command component provides a fast, composable, unstyled command menu for React. Built on top of cmdk, it's perfect for creating command palettes, search interfaces, and quick action menus.

Basic Usage

With Icons and Shortcuts

Command Dialog

File Search Example

Properties

Command

PropertyTypeDescription
classNamestringAdditional CSS classes.
childrenReactNodeCommand content.

CommandDialog

PropertyTypeDescription
openbooleanWhether the dialog is open.
onOpenChange(open: boolean) => voidCallback when open state changes.
childrenReactNodeDialog content.

CommandInput

PropertyTypeDescription
placeholderstringInput placeholder text.
valuestringInput value (controlled).
onValueChange(value: string) => voidCallback when value changes.

CommandItem

PropertyTypeDescription
onSelect() => voidCallback when item is selected.
disabledbooleanWhether the item is disabled.
valuestringItem value for filtering.
childrenReactNodeItem content.

CommandGroup

PropertyTypeDescription
headingstringGroup heading text.
childrenReactNodeGroup items.

CommandShortcut

PropertyTypeDescription
childrenReactNodeShortcut text (e.g., "⌘K").

Features

Fast Filtering

  • Built-in fuzzy search and filtering
  • Instant results as you type
  • Customizable search algorithm

Keyboard Navigation

  • Arrow keys to navigate items
  • Enter to select items
  • Escape to close dialog
  • Tab to cycle through groups

Accessibility

  • Full screen reader support
  • Proper ARIA attributes
  • Focus management
  • Keyboard shortcuts

Customization

  • Unstyled by default
  • Easy to theme and customize
  • Flexible component composition

Common Use Cases

The Command component is perfect for:

  • Command palettes - Quick access to app functions
  • File search - Navigate through project files
  • Global search - Search across different content types
  • Quick actions - Keyboard shortcuts for power users
  • Navigation menus - Fast navigation between pages
  • Settings search - Find specific configuration options
  • Documentation search - Search through help content

Best Practices

  1. Provide clear shortcuts - Use recognizable keyboard shortcuts
  2. Group related items - Organize commands into logical groups
  3. Include icons - Visual cues help with recognition
  4. Keep it fast - Ensure search results appear instantly
  5. Handle empty states - Provide helpful "no results" messages
  6. Use consistent naming - Keep command names predictable
  7. Test keyboard navigation - Ensure full keyboard accessibility