NOCTA UI

Command Palette

A command palette modal (Cmd/Ctrl+K) for quick actions and navigation with search, grouping, and full keyboard accessibility

Installation

Install the Command Palette component using the nocta-ui CLI:

npx nocta-ui add command-k

Import the component:

import { CommandK } from '@/components/ui/command-k';

Example

The Command Palette provides a fast, searchable modal for navigating and triggering actions using the keyboard.

Or press ⌘K / Ctrl+K

Keyboard Shortcuts

  • Open: platform-default ⌘K (macOS) / Ctrl+K (Windows/Linux)
  • Navigate: ↑/↓
  • Confirm: Enter
  • First/Last: Home / End
  • Close: Escape

Customizing the open hotkey

// Require Cmd+P on macOS, Ctrl+P on Windows/Linux
<CommandK hotkey={{ key: 'p' }} />

// Explicit modifier (always Cmd)
<CommandK hotkey={{ key: 'k', metaKey: true }} />

// Explicit modifier (always Ctrl)
<CommandK hotkey={{ key: 'k', ctrlKey: true }} />

Controlled vs Hotkey

You can control visibility with open/onOpenChange or rely solely on the global hotkey.

const [open, setOpen] = useState(false);

<CommandK open={open} onOpenChange={setOpen} items={items} />
// No local state — palette opens with Cmd/Ctrl+K
<CommandK items={items} />

API Reference

CommandK

PropTypeDefaultDescription
itemsCommandKItem[]List of entries to render
openbooleanControlled open state
defaultOpenbooleanfalseInitial open state
onOpenChange(open: boolean) => voidCallback when open state changes
placeholderstring'Type a command or search...'Search input placeholder
emptyMessagestring'No results'Message when no results match
closeOnActionbooleantrueClose palette after selection
size'sm' | 'md' | 'lg' | 'xl' | 'full''xl'Dialog size variant
classNamestring''Extra classes for DialogContent wrapper
listClassNamestring''Extra classes for results list
autoFocusbooleantrueFocus search input when opened
hotkey{ key: string; metaKey?: boolean; ctrlKey?: boolean; }{ key: 'k' }Open shortcut; when no modifier specified, uses platform default (⌘/Ctrl)
onSelect(item: CommandKItem) => voidCalled on item selection

CommandKItem

PropTypeDefaultDescription
idstringautoOptional unique ID
labelstringDisplay label
groupstring'General'Group header label
descriptionstring''Secondary description text
keywordsstring[][]Additional searchable terms
iconReact.ReactNodeOptional icon
shortcutstring[][]Visual shortcut hints
disabledbooleanfalseDisable selection
action() => voidAction executed on select