Command Palette
Base UIGrouped commands with a loose filter, run entirely from the keyboard.
Arrows to move, Enter to run, Esc to close
Install
$ npx shadcn@latest add https://spotcheckui.com/r/command-palette.jsonAlso installs @base-ui/react.
Usage
"use client"
import { useState } from "react"
import { CommandPalette, type CommandGroup } from "@/components/spotcheck/command-palette"
const groups: CommandGroup[] = [
{
label: "Actions",
commands: [
{ id: "new", label: "New eval run", shortcut: "N", onSelect: createRun },
{ id: "export", label: "Export as CSV", keywords: "download", onSelect: exportCsv },
],
},
]
export function App() {
const [open, setOpen] = useState(false)
return <CommandPalette groups={groups} open={open} onOpenChange={setOpen} />
}It matches labels first, then keywords, then letters in order, so "nrn" finds "New eval run".
The site's own search on this page is this component. Press ⌘K to try it.
Pass hotkey={false} if something else opens it.
Props
- groups * Required
CommandGroup[]Default —The commands, in display order. - open * Required
booleanDefault —Whether the palette is showing. - onOpenChange * Required
(open: boolean) => voidDefault —Runs when the palette should open or close. - hotkey
string | falseDefault kOpens with Cmd or Ctrl plus this key. Pass false to bind no key. - label
stringDefault Command paletteNames the dialog for screen readers. - placeholder
stringDefault Type a commandText shown in the empty input.
Keyboard
| ⌘ K | Open or close, Ctrl K on Windows and Linux |
|---|---|
| ↑ ↓ | Move through the results |
| Enter | Run the highlighted command |
| Esc | Close and return focus |
Reduced motion
The palette appears without its short slide.