shadcn.io is not affiliated with official shadcn/ui
No results found.
Suggestions
Calendar
Search Emoji
Calculator
Settings
Profile⌘P
Billing⌘B
Settings⌘S
Installation
bunx --bun shadcn@latest add https://kit.dev/r/base/command.jsonnpx shadcn@latest add https://kit.dev/r/base/command.jsonpnpm dlx shadcn@latest add https://kit.dev/r/base/command.jsonyarn shadcn@latest add https://kit.dev/r/base/command.jsonThis component depends on Dialog and Input Group. Install them first if you haven't already.
Install the following dependencies:
bun add cmdk lucide-reactnpm install cmdk lucide-reactpnpm add cmdk lucide-reactyarn add cmdk lucide-reactCopy and paste the following code into your project.
"use client";
import { Command as CommandPrimitive } from "cmdk";
import { CheckIcon, SearchIcon } from "lucide-react";
import type React from "react";
import { cn } from "@/lib/utils";
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
} from "@/registry/base/components/dialog";
import {
InputGroup,
InputGroupAddon,
} from "@/registry/base/components/input-group";
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
CommandInput
PropType
AttributeType
CommandList
PropType
AttributeType
CommandEmpty
PropType
AttributeType
CommandGroup
PropType
AttributeType
CommandSeparator
PropType
AttributeType
CommandItem
PropType
AttributeType
CommandShortcut
PropType
AttributeType