Xzero UI
Pro library

Command palette

A complete keyboard driven action surface with search, grouped results, and shortcuts.

$ pnpm dlx shadcn@4.23.0 add @xzero-ui/command-palette
Live · keyboard ready

Use it for product wide actions and navigation. Provide meaningful groups, icons, keyboard shortcuts, and handlers.

When to use

When not to use

Installation

Register both Xzero UI namespaces in your project's components.json:

{
  "registries": {
    "@xzero-ui": "https://mcp.xzero.co.uk/r/{name}.json",
    "@xzero-ui-pro": "https://mcp.xzero.co.uk/r/pro/{name}.json"
  }
}
npx shadcn@4.23.0 add @xzero-ui/command-palette

Install xzero-foundation once, and import @/components/xzero/foundation.css in your app root. No Xzero token is used by this snapshot. For sample portraits, photos, fonts, or logos, download https://mcp.xzero.co.uk/install-assets.mjs and run node xzero-install-assets.mjs <receiving-project>.

Usage

import { CommandPalette, type CommandItem } from "@/components/xzero/command-palette/command-palette";

const items: CommandItem[] = [
  { id: "new", label: "New project", group: "Create", shortcut: "N" },
  { id: "invite", label: "Invite teammate", group: "Team", keywords: ["member"] },
  { id: "theme", label: "Toggle theme", description: "Switch light and dark" },
];

export function Palette({ onClose }: { onClose: () => void }) {
  return <CommandPalette items={items} onSelect={item => run(item.id)} onClose={onClose} />;
}

Examples

Inside a dialog

<Dialog open={open} onOpenChange={setOpen}>
  <DialogContent title="Command palette">
    <CommandPalette
      items={items}
      onSelect={item => { run(item.id); setOpen(false); }}
      onClose={() => setOpen(false)}
    />
  </DialogContent>
</Dialog>

API reference

CommandPalette

An inline search-and-run panel: a combobox input over grouped, filtered results with one highlight that follows the active row.

PropTypeDefaultDescription
items (required)CommandItem[]–Commands to search. Every word of the query must match: anywhere in the label, at a word start in the description or keywords, or as letters in order across the label ("shpr" finds Share project). Label prefixes rank first, groups follow their best match, and the matched letters render in medium weight.
placeholderstring"Search commands"Input placeholder.
onSelect(item: CommandItem) => void–Called on click or Enter. The query then clears and focus returns to the input.
onClose() => void–Called on Escape with an empty query. Also renders an Esc close button.
labelstring"Command palette"Visually hidden label for the input.
autoFocusbooleanfalseFocuses the search input on mount, for a palette that opens on demand.

CommandItem

Item type: { id: string; label: string; description?: string; group?: string; keywords?: string[]; icon?: ReactNode; shortcut?: string }. Items without a group land under Actions. A shortcut such as "⇧ N" or "Shift+N" renders one keycap per key.

No props.

Keyboard interactions

KeysAction
Cmd/Ctrl + KFocuses the search input from anywhere on the page.
ArrowDown / ArrowUpMoves the active result.
Home / EndJumps to the first or last result.
EnterRuns the active result. The first result is active as soon as results show.
EscapeClears the query, or calls onClose when it is already empty.

Accessibility

Motion

Responsive behavior

Performance

Notes for AI

Guidance for AI tools

Blocks are complete, self-contained screens with sample data. Replace the sample data and connect the callbacks described above. Follow the declared prop types and do not invent props. Keep keyboard access, reduced motion support, and both light and dark themes intact when adapting it.

Full library index: https://ui.xzero.co.uk/llms.txt

Browse all components