Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Shadcn Command for React and Tailwind

Searchable command input with filtering.

Linear⌘L
Figma⌘F
Slack⌘S
YouTube⌘Y
Raycast⌘R
Settings⌘,
Help⌘?
About⌘I
Feedback⌘B
Support⌘P
Updates⌘U
Logout⌘Q
Sign out⌘O
Sign in⌘A

Installation

bunx --bun shadcn@latest add https://kit.dev/r/command.json

Anatomy

CommandRoot
├── CommandClearTrigger
├── CommandContent
├── CommandControl
├── CommandInput
├── CommandItem
│   ├── CommandItemGroup
│   │   └── CommandItemGroupLabel
│   ├── CommandItemIndicator
│   └── CommandItemText
├── CommandLabel
├── CommandList
├── CommandPositioner
└── CommandTrigger

Usage

import { useListCollection } from "@ark-ui/react/collection";
import { useFilter } from "@ark-ui/react/locale";
import {
  Command,
  CommandContent,
  CommandEmpty,
  CommandGroup,
  CommandInput,
  CommandItem,
  CommandList,
  CommandSeparator,
  CommandShortcut,
} from "@/components/ui/command";
const CommandExample = () => {
  const { contains } = useFilter({ sensitivity: "base" });

  const { collection, filter } = useListCollection({
    filter: contains,
    groupBy: (item) => item.group,
    initialItems,
  });

  const handleInputValueChange = ({ inputValue }: { inputValue: string }) => {
    filter(inputValue);
  };

  const groups = collection.group();

  return (
    <Command
      className="w-full max-w-md"
      collection={collection}
      onInputValueChange={handleInputValueChange}
    >
      <CommandInput placeholder="Search..." />
      <CommandContent>
        <CommandEmpty />
        <CommandList>
          {groups.map(([group, items], index) => (
            <CommandGroup heading={group} key={group}>
              {items.map((item) => (
                <CommandItem item={item} key={item.value}>
                  {item.label}
                  <CommandShortcut>{item.shortcut}</CommandShortcut>
                </CommandItem>
              ))}
              {index < groups.length - 1 && <CommandSeparator />}
            </CommandGroup>
          ))}
        </CommandList>
      </CommandContent>
    </Command>
  );
};

const initialItems = [
  { group: "Suggestions", label: "Linear", shortcut: "⌘L", value: "linear" },
  { group: "Suggestions", label: "Figma", shortcut: "⌘F", value: "figma" },
  { group: "Suggestions", label: "Slack", shortcut: "⌘S", value: "slack" },
  { group: "Suggestions", label: "YouTube", shortcut: "⌘Y", value: "youtube" },
  { group: "Suggestions", label: "Raycast", shortcut: "⌘R", value: "raycast" },
  { group: "Settings", label: "Settings", shortcut: "⌘,", value: "settings" },
  { group: "Settings", label: "Help", shortcut: "⌘?", value: "help" },
  { group: "Settings", label: "About", shortcut: "⌘I", value: "about" },
  { group: "Settings", label: "Feedback", shortcut: "⌘B", value: "feedback" },
  { group: "Settings", label: "Support", shortcut: "⌘P", value: "support" },
  { group: "Settings", label: "Updates", shortcut: "⌘U", value: "updates" },
  { group: "Settings", label: "Logout", shortcut: "⌘Q", value: "logout" },
  { group: "Settings", label: "Sign out", shortcut: "⌘O", value: "sign out" },
  { group: "Settings", label: "Sign in", shortcut: "⌘A", value: "sign in" },
];

Accessibility

KeyDescription
ArrowDown
Move down.
ArrowUp
Move up.
Home
Go to the start.
End
Go to the end.
Enter
Activate the focused item.
Escape
Dismiss.
Space
Activate the focused control.
ArrowLeft
Move left.
ArrowRight
Move right.

Demos

Context

Controlled

Dialog

Groups

Root Provider

Scrollable

Shortcuts

API Reference

CommandContent

div

PropType
AttributeType
CSS variableType

CommandInput

input

PropType
AttributeType

CommandItem

div

PropType
AttributeType

CommandDialog

AttributeType

CommandDialogTrigger

PropType
AttributeType

CommandDialogContent

div

PropType
AttributeType

CommandList

PropType
AttributeType

CommandEmpty

PropType
AttributeType

CommandGroup

PropType
AttributeType

CommandGroupLabel

PropType
AttributeType

CommandSeparator

PropType
AttributeType

CommandShortcut

PropType
AttributeType

CommandFooter

PropType
AttributeType