Menu

Command palette

⌘K search & actions. 2 states.

esc

↑↓ to navigate · ↵ to select · esc to close

Installation

$ npx uix-ui@latest add command-palette

This copies the file into components/ui/command-palette.tsx in your project. npx shadcn@latest add @uix/command-palette works too.

Usage

command-palette.tsx
import { CommandPalette } from "@/components/ui/command-palette";

<div style={{ display: "grid", gap: 10, justifyItems: "center" }}>
  <Button variant="soft" onClick={() => setOpen(true)}>Search <Kbd size="sm">⌘K</Kbd></Button>
  {last ? <span className="text-body-small text-fg-secondary">You picked: {last}</span> : null}
  <CommandPalette
    open={open}
    onClose={() => setOpen(false)}
    groups={[
      { heading: "Go to", items: [{ id: "orders", label: "Orders", icon: <Inbox />, onSelect: () => setLast("Orders") }, { id: "search", label: "Find a tea", icon: <Search />, shortcut: ["⌘", "F"], onSelect: () => setLast("Find a tea") }] },
      { heading: "Actions", items: [{ id: "new", label: "New order", icon: <Zap />, shortcut: ["⌘", "N"], onSelect: () => setLast("New order") }] },
    ]}
  />
</div>

Props

PropTypeDefaultDescription
openboolean–
onClose() => void–
groupsCommandGroup[]–
placeholderstring"Type a command or search…"
emptyTextstring"No results found."Shown when nothing matches.
showFooterbooleantrueHint bar under the list.

Everything else is passed to the root element, so className, aria-* and event handlers work as usual.

Dependencies

Installed for you by the CLI.

  • class-variance-authority
  • clsx
  • tailwind-merge
  • lib/utils.ts
  • components/ui/icons.tsx
esc

↑↓ to navigate · ↵ to select · esc to close