View fulldotdev/ui on GitHub

Command

Command menu for search and quick actions.

Installation

npx shadcn@latest add @fulldev/command

Usage

import {
  Command,
  CommandDialog,
  CommandEmpty,
  CommandGroup,
  CommandInput,
  CommandItem,
  CommandList,
  CommandSeparator,
  CommandShortcut,
} from "@/components/ui/command"
<Command class="max-w-sm rounded-lg border">
  <CommandInput placeholder="Type a command or search..." />
  <CommandList>
    <CommandEmpty>No results found.</CommandEmpty>
    <CommandGroup heading="Suggestions">
      <CommandItem>Calendar</CommandItem>
      <CommandItem>Search Emoji</CommandItem>
      <CommandItem>Calculator</CommandItem>
    </CommandGroup>
    <CommandSeparator />
    <CommandGroup heading="Settings">
      <CommandItem>Profile</CommandItem>
      <CommandItem>Billing</CommandItem>
      <CommandItem>Settings</CommandItem>
    </CommandGroup>
  </CommandList>
</Command>

Filtering, keyboard navigation and selection run on Data Slot. A CommandItem with href renders a link that Enter follows.

Composition

Command
├── CommandInput
└── CommandList
    ├── CommandEmpty
    ├── CommandGroup
    │   ├── CommandItem
    │   └── CommandItem
    ├── CommandSeparator
    └── CommandGroup
        ├── CommandItem
        └── CommandItem

Command Dialog

CommandDialog includes its own Dialog root. Put a DialogTrigger in its trigger slot; wrapping it in another Dialog creates an outer root with no content, which Data Slot rejects. Focus starts in the search field, the first focusable element while showCloseButton is false (the default).

<CommandDialog>
  <DialogTrigger slot="trigger" variant="outline">
    Open Menu
  </DialogTrigger>
  <Command>
    <CommandInput placeholder="Type a command or search..." />
    <CommandList>...</CommandList>
  </Command>
</CommandDialog>

Basic

A simple command menu in a dialog.

Shortcuts

Groups

A command menu with groups, icons and separators.

Scrollable

Scrollable command menu with multiple items.

RTL

API Reference

Source: src/components/ui/command

Command propTypeDescription
labelstringAccessible label
defaultValuestringInitially selected item value
defaultSearchstringInitial search text
shouldFilterbooleanSet false to filter items yourself
loopbooleanWrap keyboard navigation
disablePointerSelectionbooleanDo not select items on hover
vimBindingsbooleanCtrl+J/K/N/P navigation (on by default)
CommandItem propTypeDescription
valuestringValue used for filtering
keywordsstring | string[]Extra search terms
disabledbooleanNot selectable
hrefstringRender a link
forceMountbooleanAlways visible, even if filtered

CommandGroup takes heading, value and forceMount. CommandDialog takes the Dialog props plus title, description (screen reader only), contentClass and showCloseButton (default false). See the Data Slot docs for events.