CommandBox
A command palette for quick navigation, search, and actions with keyboard support.
Usage
Command Palette
Press Ctrl+Shift+P or click the button
Interactive
Use arrow keys to navigate, Enter to select, Escape to close
Inline CommandBox
Without overlay backdrop
Embedded
With Descriptions
Items with additional context
Simple List
Without groups or shortcuts
Loading State
Async command loading
import { CommandBox } from "@/components/ui/commandbox"
const items = [
{ id: "home", title: "Go to Home", shortcut: ["⌘", "H"] },
{ id: "search", title: "Search", shortcut: ["⌘", "K"] },
]
export function Example() {
return (
<CommandBox
items={items}
onSelect={(item) => console.log(item.title)}
/>
)
}Installation
Copy the component file into your project:
// Copy the full component codeFeatures
- Keyboard Navigation — Arrow keys, Enter to select, Escape to close
- Search Filtering — Real-time filtering with pluggable filter function
- Grouping — Auto-group items via
groupproperty or explicitgroupsprop - Shortcuts — Display keyboard shortcuts next to items
- Variants —
default,bordered,elevated,minimal
Props
CommandBox
| Prop | Type | Default | Description |
|---|---|---|---|
items | CommandItem[] | [] | Flat list of command items. |
groups | CommandGroup[] | [] | Grouped command items. |
placeholder | string | "Type a command or search..." | Search input placeholder. |
emptyText | string | "No results found." | Text shown when no results match. |
variant | default | bordered | elevated | minimal | default | Visual variant. |
size | small | medium | large | medium | Size of the command box. |
open | boolean | false | Control open state. |
onOpenChange | (open: boolean) => void | — | Callback when open state changes. |
onSelect | (item: CommandItem) => void | — | Callback when an item is selected. |
filter | (value, search) => number | built-in | Custom filter function. |
disabled | boolean | false | Disable the command box. |
showShortcuts | boolean | true | Show keyboard shortcuts on items. |
maxHeight | string | "400px" | Max height of the dropdown. |
CommandItem
| Property | Type | Description |
|---|---|---|
id | string | Unique identifier. |
title | string | Display title. |
description | string | Optional description text. |
icon | ReactNode | Optional icon element. |
shortcut | string[] | Keyboard shortcut keys to display. |
group | string | Group name for auto-grouping. |
disabled | boolean | Disable this item. |
onSelect | () => void | Item-level select callback. |