Command

Navigation
Keyboard
cmdk

A command palette component for quick navigation and actions. Built on cmdk for fast, accessible keyboard-first interactions.

Basic Command

A static command menu with groups and items

Command Dialog

Command palette in a dialog overlay, triggered by keyboard shortcut

Press K to open the command palette

With Keyboard Shortcuts

Display keyboard shortcuts alongside command items

Usage

How to implement the Command component

import {
  Command,
  CommandDialog,
  CommandEmpty,
  CommandGroup,
  CommandInput,
  CommandItem,
  CommandList,
  CommandSeparator,
  CommandShortcut,
} from '@/components/ui/command'

// Basic usage
<Command>
  <CommandInput placeholder="Type a command..." />
  <CommandList>
    <CommandEmpty>No results found.</CommandEmpty>
    <CommandGroup heading="Suggestions">
      <CommandItem>
        <Calendar className="mr-2 h-4 w-4" />
        <span>Calendar</span>
      </CommandItem>
    </CommandGroup>
  </CommandList>
</Command>

// As a dialog with keyboard shortcut
const [open, setOpen] = React.useState(false)

React.useEffect(() => {
  const down = (e: KeyboardEvent) => {
    if (e.key === 'k' && (e.metaKey || e.ctrlKey)) {
      e.preventDefault()
      setOpen((open) => !open)
    }
  }
  document.addEventListener('keydown', down)
  return () => document.removeEventListener('keydown', down)
}, [])

<CommandDialog open={open} onOpenChange={setOpen}>
  <CommandInput placeholder="Search..." />
  <CommandList>
    <CommandGroup heading="Actions">
      <CommandItem onSelect={() => setOpen(false)}>
        <span>Action</span>
        <CommandShortcut>⌘A</CommandShortcut>
      </CommandItem>
    </CommandGroup>
  </CommandList>
</CommandDialog>

Component Props

API reference for Command components

PropTypeDefaultDescription
CommandReact.ComponentProps<typeof CommandPrimitive>Root command container, accepts all cmdk props
CommandDialog{ open, onOpenChange, children }Command in a dialog overlay
CommandInputReact.ComponentProps<typeof CommandPrimitive.Input>Search input field
CommandListReact.ComponentProps<typeof CommandPrimitive.List>Scrollable list container
CommandEmptyReact.ComponentProps<typeof CommandPrimitive.Empty>Shown when no results
CommandGroup{ heading?: string } & propsGroup of related items
CommandItem{ onSelect?: () => void } & propsIndividual command item
CommandShortcutReact.HTMLAttributes<HTMLSpanElement>Keyboard shortcut display
CommandSeparatorReact.ComponentProps<typeof CommandPrimitive.Separator>Visual separator between groups

Features

Command palette capabilities

  • Fuzzy search: Built-in fuzzy filtering of command items
  • Keyboard navigation: Arrow keys, Enter, and Escape support
  • Command+K shortcut: Standard keyboard shortcut integration
  • Grouped items: Organize commands into logical groups
  • Shortcuts display: Show keyboard shortcuts for commands
  • Dialog mode: Open as overlay dialog or inline
  • Accessible: Full ARIA support for screen readers
  • Dark mode: Automatic dark mode styling

Related Components