Skip to content

Command Palette

Global search and jump on Cmd or Ctrl K: grouped results, prefix filters and keyboard navigation.

Base UI4.6 kB gzipSource Registry JSON

Search and jump

Picked: nothing yet

Installation

npx shadcn@latest add https://sproutboat.com/ikada/r/command-palette.json

The CLI writes components/ikada/command-palette.tsx and merges the ikada theme into your CSS. It also installs the components it is built from: Kbd and Spinner. Or take it from the package: import { CommandPalette } from "@sproutboat/ikada";

Usage

import { CommandPalette } from "@/components/ikada/command-palette";

const groups = [
  {
    id: "sprouts",
    label: "Sprouts",
    items: [
      { id: "robin", label: "robin", hint: "eu-west · production", icon: <RocketIcon /> },
      { id: "wren", label: "wren", hint: "us-east · production", icon: <RocketIcon /> },
      { id: "finch", label: "finch", hint: "eu-west · staging", icon: <RocketIcon /> },
    ],
  },
];

function Search() {
  const [open, setOpen] = useState(false);
  useCommandPaletteShortcut(() => setOpen((o) => !o));
  return (
    <>
      <Button onClick={() => setOpen(true)} aria-keyshortcuts="Meta+K Control+K">
        <SearchIcon />
        Search
        <Kbd aria-hidden="true">{shortcutLabel()}</Kbd>
      </Button>
      <CommandPalette
        open={open}
        onOpenChange={setOpen}
        groups={groups}
        onSelect={(item) => navigate(item.id)}
      />
    </>
  );
}

Examples

Search and jump

Opens with the button or the shortcut. Arrow keys move, Enter picks, Escape closes. Results are filtered as you type.
Picked: nothing yet

Recents and prefixes

Recents show while the query is empty. Type d1: to narrow the search to one kind of thing.
Picked: nothing yet

Props

CommandPaletteProps
PropTypeDescription
openrequiredbooleanWhether it is open (controlled).
onOpenChangerequired(open: boolean) => voidCalled with the new open state when it opens or closes.
groupsrequiredreadonly PaletteGroup[]Results to show, in order: each group a heading and its items.
recentsreadonly PaletteItem[]Shown first while the query is empty. Default `[]`.
prefixesreadonly PalettePrefix[]Scopes typed as `scope:` that narrow the search, shown as a chip. Default `[]`.
onSelectrequired(item: PaletteItem) => voidCalled with the chosen item; the palette closes after it.
loadingbooleanShows a spinner while results are fetched. Default `false`.
placeholderstringPlaceholder of the search input. Default `Search projects, versions, storage…`.
labelstringName for screen readers. Default `Command palette`.

Source: src/components/command-palette.tsx