CommandPalette
CommandPalette is the ⌘K launcher. It composes Dialog for the modal shell and adds fuzzy filtering, sections, recent-item tracking, and a hook for the global keyboard shortcut.
What it is
A compound component over a flat list of Command objects. CommandPalette.Root holds the open
state, the search input value, and the filtered, grouped result set; CommandPalette.Input
renders the search box; CommandPalette.List renders the grouped results. The Root composes
Dialog underneath, so the palette is modal — focus-trapped,
scrim-backed, Escape-dismissible.
useCommandPaletteShortcut is a separate hook for the global activation key. It is not part of
the compound API — call it wherever you own the open state.
Install
Anatomy
API
CommandPalette.Root
CommandPalette.Root
stablefunction CommandPalette.Root(props: CommandPaletteRootProps): JSX.Element
The full command set. Filtering and grouping run against this array.
The open state, controlled or uncontrolled — same shape as Dialog.Root.
Controlled recent-command ids. When omitted, an internal recents list is kept.
Called when the recents list changes — persist it to drive controlled recents.
Cap on the internal recents list.
Override the fuzzy matcher. Return `null` for no match or a score where higher is better.
CommandPalette.Input
Renders the search box. Pass a placeholder, or pass a single element child to use your own
input — CommandPalette clones it with the combobox ARIA wiring and the keyboard handlers.
CommandPalette.List
CommandPalette.List
stablefunction CommandPalette.List(props: CommandPaletteListProps): JSX.Element
Renders one command row. `info` carries `highlighted`, `isRecent`, and `index`.
Renders a section heading. Defaults to a plain div with the section name.
Rendered when the filter matches nothing.
Command
useCommandPaletteShortcut
useCommandPaletteShortcut
stablefunction useCommandPaletteShortcut(combo: string, handler: () => void): void
Registers a global keydown listener for combo — e.g. 'mod+k', where mod is ⌘ on macOS and
Ctrl elsewhere. Pass a memoised handler so the listener does not churn every render.
defaultFuzzyMatch
The built-in matcher, exported so a custom matcher can fall back to it. Substring matches
outrank scattered-character matches; earlier positions outrank later ones.
Accessibility
The input is a role="combobox" with aria-expanded, aria-controls, and
aria-activedescendant pointing at the highlighted row. The list is a role="listbox" of
role="option" rows. The arrow keys move the highlight, Enter activates, and — because the
palette composes Dialog — focus is trapped while it is open and restored on close.
The shortcut is an enhancement, not the only door. Provide a visible affordance — a button, a menu item — that opens the palette too, so users who cannot or do not know the keyboard shortcut still reach it.
Examples
A file-and-edit palette: