Skip to content
English

How it works

Matching tries a contiguous run first, then the letters in order (at most three pieces), and falls back to keywords. Focus stays in the field; a single highlight element glides to the active option with transform and height, and keeps it in view by adjusting the list's own scroll, never the page's.

Use it for

  • Apps with many pages or actions where power users want to jump by keyboard.
  • A single entry point for search, navigation and commands.

Look elsewhere when

  • Searching large remote data with filters: use a full search page.
  • Touch-first apps without a keyboard: a visible menu is easier.

Usage

import { useState } from 'react'
import { CommandPalette } from './CommandPalette.jsx'

export function AppSearch() {
  const [open, setOpen] = useState(false)
  return (
    <CommandPalette
      open={open}
      onOpenChange={setOpen}
      recent={[{ id: 'roadmap', label: 'Q4 roadmap', hint: 'Projects' }]}
      groups={[
        { id: 'pages', label: 'Pages', items: [{ id: 'guide', label: 'Onboarding guide', keywords: ['welcome'] }] },
        { id: 'actions', label: 'Actions', items: [{ id: 'new', label: 'New page', shortcut: ['⌘', 'N'] }] },
      ]}
      onSelect={(item) => console.log(item.id)}
    />
  )
}

Props

PropTypeDefaultWhat it does
openboolean—Whether the palette is shown.
onOpenChange(open: boolean) => void—Called on the hotkey, Escape, a click outside or after a choice.
groups{ id, label, items: { id, label, hint?, icon?, shortcut?: string[], keywords?: string[], disabled? }[] }[]—Grouped commands; empty groups are hidden while searching.
recentItem[]—Shown as the first group while the field is empty.
onSelect(item) => void—Called with the chosen item.
labelsobject—Replaces built-in text: placeholder, dialog, recent, empty ({query} is replaced), emptyHint, navigate, open, close.
hotkeystring | false'k'Letter that toggles the palette with ⌘ or Ctrl; false turns it off.
containedbooleanfalseFill the nearest positioned ancestor instead of the viewport.
footerbooleantrueShow the keyboard hint bar.

Accessibility

  • role dialog with aria-modal; the field is a combobox that controls a listbox, with grouped role option rows.
  • aria-activedescendant announces the active option while focus stays in the field.
  • Up and Down (or Ctrl+N and Ctrl+P) move, Home and End jump, Enter chooses, Escape clears the query and then closes; Tab stays inside.
  • Focus moves to the field on open and returns to the previous element on close.
  • The empty state is a role status message.
  • With reduced motion the panel only fades and the highlight jumps.

Motion

Panel enters 260ms ease-out from 6px above at 0.98 scale, leaves in 140ms; the highlight glides 200ms ease-out; the enter glyph slides in 4px.

Add it to your project

Copy the prompt into Codex or Claude Code. The agent reads the published source, shows you what it will write and adds the component next to your own.

CommandPalette.jsxcommand-palette.csstokens.cssREADME.md

Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.

Navigation
Dock bar comes with Pro. Its preview shows once you unlock it.