Command Palette

@allem-ui/command

Spotlight-style command palette with keyboard navigation, grouped results, and shortcut badges. Opens with ⌘K.

Installation

npm install @allem-ui/command

Add the @source directive to your CSS so Tailwind generates the component classes:

@source "@allem-ui/command";

Basic Usage

A flat list of commands without groups. Click the button to open.

Grouped with Shortcuts

Click the button or press ⌘K to open. Items are organized into groups with keyboard shortcut badges.

Built-in Behavior

FeatureDescription
Keyboard navigation↑↓ to navigate items, ↵ to select, Esc to close. Wraps around at edges.
Shortcuts footerBuilt-in footer showing navigation hints (↑↓ navigate, ↵ select, esc close).
Backdrop dismissClicking outside the palette closes it automatically.
Scroll lockBody scroll is locked while the palette is open.
Auto-focusInput is automatically focused when the palette opens.
Clear buttonAn × button appears in the input when it has a value.
Auto-scrollActive item scrolls into view during keyboard navigation.
AnimationsFade-in and slide-up entrance animations.
AccessibilityFull ARIA support — role="dialog", aria-modal, aria-selected on items, role="listbox".

CommandPalette Props

PropTypeDefaultDescription
open*booleanWhether the palette is open
onOpenChange*(open: boolean) => voidCallback when open state changes
classNamestringAdditional CSS classes
children*ReactNodeCommandInput, CommandList, etc.

CommandInput Props

PropTypeDefaultDescription
value*stringCurrent input value
onValueChange*(value: string) => voidCallback when input changes
placeholderstring"Type a command or search..."Input placeholder text
classNamestringAdditional CSS classes

CommandItem Props

PropTypeDefaultDescription
onSelect*() => voidCalled when item is selected
iconReactNodeIcon on the left
shortcutstringKeyboard shortcut badge
disabledbooleanfalseDisable the item
activebooleanfalseWhether the item is currently active
classNamestringAdditional CSS classes

CommandGroup Props

PropTypeDefaultDescription
heading*stringGroup heading text
classNamestringAdditional CSS classes
children*ReactNodeCommandItem elements

CommandList Props

PropTypeDefaultDescription
classNamestringAdditional CSS classes
children*ReactNodeCommandGroup, CommandItem, or CommandEmpty elements

CommandEmpty Props

PropTypeDefaultDescription
classNamestringAdditional CSS classes
childrenReactNode"No results found."Custom empty state message

useCommandPalette

Hook that manages open state and registers a global ⌘K (Ctrl+K) keyboard shortcut.

PropTypeDefaultDescription
shortcutstring"k"Key to combine with ⌘/Ctrl to toggle

Return Value

PropTypeDefaultDescription
isOpenbooleanCurrent open state
open() => voidOpen the palette
close() => voidClose the palette
toggle() => voidToggle the palette
setIsOpen(value: boolean) => voidSet open state directly