Skip to content
Pixelbits
Docs / Command palette
Overlays

Command palette

A searchable list of commands in a modal (⌘K). Typing filters by label, group and keywords (all words must match); arrows move, Enter runs, Escape closes. Focus stays in the search field (aria-activedescendant).

Installation

npm: import
import { CommandPalette } from "pixelbits/command-palette";
shadcn: copy the source
npx shadcn add https://pixelbits.ali-moradi-develop.com/r/command-palette.json

API

<CommandPalette>

A searchable list of commands in a modal (⌘K). Typing filters by label, group and keywords (all words must match); arrows move, Enter runs, Escape closes. Focus stays in the search field (aria-activedescendant).

Example
<CommandPalette
  commands={[
    { id: "theme", label: "Switch to light theme", group: "Actions", shortcut: "⌘ L", onSelect: toggleTheme },
    { id: "button", label: "Pixel button", group: "Components", onSelect: () => go("/button") },
  ]}
/>
PropTypeDefaultDescription
commands*Command[]—

All commands, in display order.

openboolean—

Whether it is open (controlled).

defaultOpenbooleanfalse

Open on first render (uncontrolled).

onOpenChange(open: boolean) => void—

Called when it opens or closes.

hotkeystring | false"mod+k"

A global shortcut that opens it: "mod+k" means ⌘K on macOS and Ctrl+K elsewhere. false for none.

placeholderstring"Type a command or search…"

Placeholder of the search field.

emptyTextReactNode"No results"

Shown when nothing matches.

labelstring"Command palette"

Accessible name of the dialog.

classNamestring—

Extra classes for the root element.