Thinking UI

Command PalettePRO

A ⌘K dialog with grouped commands, forgiving search and a highlight that glides as you arrow through.

Code

1 file · 456 lines of TypeScriptPRO

Command Palette is part of Pro

Get its source, the one-paste agent prompt and all 113 components, for a one-time $99.

Motion notes

  • The panel scales up from just below full size and sharpens out of a blur on the base spring, while the backdrop blurs the page behind it. It reads as focus moving forward, not a window popping open.
  • The highlight is one shared element that slides between rows. As you filter, the panel eases to its new height instead of snapping, so results never jump under your eyes.
  • Matching is forgiving: prefix beats word start beats substring beats letters in order ("tws" finds "Toggle web search"). Matched letters are brightened, so you can see why something matched.
  • Follows the combobox pattern: arrows (or Ctrl+N / Ctrl+P) move, Enter runs, Escape clears the query and then closes. Focus returns to where it was. With reduced motion, it only fades and the highlight jumps.

Usage

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

  <CommandPalette
    open={open}
    onOpenChange={setOpen}
    commands={[
      { id: "new", group: "Chat", label: "New chat", shortcut: ["⌘", "N"], onSelect: newChat },
      { id: "model", group: "Model", label: "Switch model", keywords: ["claude", "gpt"], onSelect: openModels },
      { id: "web", group: "Model", label: "Toggle web search", hint: webSearch ? "On" : "Off", onSelect: toggleWeb },
    ]}
  />

Props

PropTypeDefaultDescription
commandsCommandItem[]—{ id, label, group?, icon?, keywords?, hint?, shortcut?: string[], onSelect? }
openboolean—Controlled open state. Leave it out for uncontrolled use.
defaultOpenbooleanfalseInitial open state when uncontrolled.
onOpenChange(open: boolean) => void—Called on ⌘K, Escape, backdrop click or after running a command.
onSelect(command: CommandItem) => void—Called with the chosen command, after its own onSelect.
querystring—Controlled search text.
onQueryChange(query: string) => void—Called as the search text changes.
activeIdstring—Controlled highlighted command. Falls back to the first result when filtered out.
onActiveIdChange(id: string) => void—Called as the highlight moves.
inlinebooleanfalseRender in place, filling the nearest positioned parent, instead of a fixed portal on document.body.
hotkeystring | false"k" (false when inline)Key that toggles the palette together with ⌘ or Ctrl.
placeholderstring"Search commands…"Input placeholder.
keepOpenbooleanfalseStay open after running a command.
maxListHeightnumber296Max height of the results list in px.
classNamestring—Classes for the panel.