Skip to content
Drivn logoDrivn

Command

Searchable command menu powered by cmdk with filtering, keyboard navigation, grouping, and dialog mode.

Preview

Installation

npx drivn add command

Usage

Import Command and compose with sub-components.

1import { Command } from "@/components/ui/command"
2import { Calendar, Search, Smile, User, CreditCard, Settings } from "lucide-react"
3
4export default function Page() {
5 return (
6 <Command>
7 <Command.Input placeholder="Type a command..." />
8 <Command.List>
9 <Command.Empty />
10 <Command.Group heading="Suggestions">
11 <Command.Item>
12 <Calendar className="w-4 h-4" />
13 Calendar
14 </Command.Item>
15 <Command.Item>
16 <Search className="w-4 h-4" />
17 Search
18 </Command.Item>
19 <Command.Item>
20 <Smile className="w-4 h-4" />
21 Emoji
22 </Command.Item>
23 </Command.Group>
24 <Command.Separator />
25 <Command.Group heading="Settings">
26 <Command.Item>
27 <User className="w-4 h-4" />
28 Profile
29 </Command.Item>
30 <Command.Item>
31 <CreditCard className="w-4 h-4" />
32 Billing
33 </Command.Item>
34 <Command.Item>
35 <Settings className="w-4 h-4" />
36 Preferences
37 </Command.Item>
38 </Command.Group>
39 </Command.List>
40 </Command>
41 )
42}

Groups

Organize items into labeled groups with separators.

Shortcuts

Display keyboard shortcuts next to items with Command.Shortcut.

Dialog

Ctrl+K / Cmd+K is built in. Pass open and onOpenChange to control state.

Empty State

Customize the message shown when no results match.

API Reference

Command

PropTypeDefaultDescription
labelstringAccessible label for the command menu (screen readers)
shouldFilterbooleantrueWhether cmdk should filter items automatically
filter(value: string, search: string) => numberCustom filter function. Return 1 for match, 0 for no match
valuestringControlled value of the selected item
onValueChange(value: string) => voidCallback when the selected item changes
classNamestringAdditional CSS classes for the root element

Command.Input

PropTypeDefaultDescription
placeholderstringPlaceholder text for the search input
valuestringControlled value of the search input
onValueChange(search: string) => voidCallback when the search input value changes
classNamestringAdditional CSS classes for the input element

Command.Item

PropTypeDefaultDescription
valuestringUnique value for the item (defaults to text content)
onSelect(value: string) => voidCallback when the item is selected via click or Enter
disabledbooleanfalseWhether the item is disabled
keywordsstring[]Additional search keywords not visible in the UI
classNamestringAdditional CSS classes for the item element

Command.Group

PropTypeDefaultDescription
headingstringGroup heading displayed above the items
forceMountbooleanKeep the group visible even when no items match
classNamestringAdditional CSS classes for the group element

Command.Dialog

PropTypeDefaultDescription
openbooleanControlled open state of the dialog
onOpenChange(open: boolean) => voidCallback when the dialog open state changes
labelstringAccessible label for the command menu inside the dialog
classNamestringAdditional CSS classes for the dialog content

Command.Separator

PropTypeDefaultDescription
alwaysRenderbooleanKeep the separator visible even when adjacent groups are filtered out
classNamestringAdditional CSS classes for the separator element