shadcn.io is not affiliated with official shadcn/ui
Calendar
Search Emoji
Calculator
Profile⌘P
Billing⌘B
Settings⌘S
Installation
bunx --bun shadcn@latest add https://kit.dev/r/aria/command.jsonnpx shadcn@latest add https://kit.dev/r/aria/command.jsonpnpm dlx shadcn@latest add https://kit.dev/r/aria/command.jsonyarn shadcn@latest add https://kit.dev/r/aria/command.jsonThis component depends on Dialog and Input Group. Install them first if you haven't already.
Install the following dependencies:
bun add react-aria-components lucide-reactnpm install react-aria-components lucide-reactpnpm add react-aria-components lucide-reactyarn add react-aria-components lucide-reactCopy and paste the following code into your project.
"use client";
import { CheckIcon, SearchIcon } from "lucide-react";
import type React from "react";
import {
Autocomplete,
Collection,
composeRenderProps,
Header,
Input,
Menu,
MenuItem,
MenuSection,
SearchField,
Separator,
useFilter,
type AutocompleteProps,
type InputProps,Update the import paths to match your project setup.
Anatomy
CommandRoot
├── CommandClearTrigger
├── CommandContent
├── CommandControl
├── CommandInput
├── CommandItem
│ ├── CommandGroup
│ │ └── CommandGroupLabel
│ ├── CommandItemIndicator
│ └── CommandItemText
├── CommandLabel
├── CommandList
├── CommandPositioner
└── CommandTriggerUsage
import { useListCollection } from "@ark-ui/react/collection";
import { useFilter } from "@ark-ui/react/locale";
import {
CalculatorIcon,
CalendarIcon,
CreditCardIcon,
SettingsIcon,
SmileIcon,
UserIcon,
} from "lucide-react";
import { Fragment } from "react";
import {
Command,
CommandContent,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
CommandSeparator,
CommandShortcut,
} from "@/components/ui/command";const initialItems = [
{
group: "Suggestions",
icon: CalendarIcon,
label: "Calendar",
value: "calendar",
},
{
group: "Suggestions",
icon: SmileIcon,
label: "Search Emoji",
value: "emoji",
},
{
disabled: true,
group: "Suggestions",
icon: CalculatorIcon,
label: "Calculator",
value: "calculator",
},
{
group: "Settings",
icon: UserIcon,
label: "Profile",
shortcut: "⌘P",
value: "profile",
},
{
group: "Settings",
icon: CreditCardIcon,
label: "Billing",
shortcut: "⌘B",
value: "billing",
},
{
group: "Settings",
icon: SettingsIcon,
label: "Settings",
shortcut: "⌘S",
value: "settings",
},
];
const CommandDemo = () => {
const { contains } = useFilter({ sensitivity: "base" });
const { collection, filter } = useListCollection({
filter: contains,
groupBy: (item) => item.group,
initialItems,
});
const handleInputValueChange = (details: { inputValue: string }) => {
filter(details.inputValue);
};
return (
<Command
className="max-w-sm rounded-lg border"
collection={collection}
onInputValueChange={handleInputValueChange}
>
<CommandInput placeholder="Type a command or search..." />
<CommandContent>
<CommandList>
<CommandEmpty>No results found.</CommandEmpty>
{collection.group().map(([group, items], index) => (
<Fragment key={group}>
{index > 0 && <CommandSeparator />}
<CommandGroup heading={group}>
{items.map((item) => {
const Icon = item.icon;
return (
<CommandItem item={item} key={item.value}>
<Icon aria-hidden="true" />
<span>{item.label}</span>
{!!item.shortcut && (
<CommandShortcut>{item.shortcut}</CommandShortcut>
)}
</CommandItem>
);
})}
</CommandGroup>
</Fragment>
))}
</CommandList>
</CommandContent>
</Command>
);
};
Accessibility
| Key | Description |
|---|---|
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
Basic
A simple command menu in a dialog.
Shortcuts
Command menu with keyboard shortcuts.
Groups
A command menu with groups, icons and separators.
Scrollable
Scrollable command menu with multiple items.
Rtl
Right-to-left command menu. See the RTL configuration guide for document direction.
API Reference
Command
PropType
AttributeType
CommandDialog
PropType
childrenReact.ReactNodeCommandInput
PropType
AttributeType
CommandList
PropType
AttributeType
CommandEmpty
PropType
AttributeType
CommandGroup
PropType
AttributeType
CommandSeparator
PropType
AttributeType
CommandItem
PropType
AttributeType
CommandShortcut
PropType
AttributeType