Skip to content

COMPONENT / command-palette

Command Palette_

⌘K / Ctrl+K dialog with a > prompt input that filters grouped commands; the highlighted row fills --signal. Built on Base UI. Requires @cybr/tokens.

Install

  1. 1. Map the @cybr namespace, once per project. Add this inside your components.json, or into its existing "registries" object. No components.json yet? Run npx shadcn@latest init first to create one.

    "registries": { "@cybr": "https://cybr-ui.com/r/{name}.json" }
  2. 2. Add components:

    $ npx shadcn@latest add @cybr/command-palette

If shadcn reports Unknown registry "@cybr", step 1 is missing from that project's components.json.

Preview

LAST RUN: —

Props

Component props
PropTypeDefaultDescription
groups{ label: string; items: { value: string; label: string; hint?: string }[] }[]—Commands in labelled groups. Typing filters by label; groups with no matches hide.
onSelect(value: string) => void—Called with the chosen item's value. The palette then closes. Navigate here, for example with your router.
defaultOpen / openbooleanfalseStarting state (uncontrolled) or the open state (controlled).
onOpenChange(open: boolean) => void—Called when the palette opens or closes, including from the shortcut.
shortcutbooleantrueWhile mounted, ⌘K or Ctrl+K anywhere on the page toggles the palette.
shortcutLabelstring"⌘K"Key-cap text on the trigger. Both ⌘K and Ctrl+K work whatever it says.
triggerReactNode | false"SEARCH"Content of the trigger button, or false for no trigger (open it with the shortcut or open).
labelstring"Command palette"Accessible name of the dialog.
placeholderstring"Type a command…"Input placeholder.
classNamestring—Extra classes on the trigger, merged after the defaults with cn().

Usage

Installs @base-ui/react. Needs the stylesheet from @cybr/tokens. After the install, import it in app/globals.css:

@import "tailwindcss";
@import "../styles/cybr-tokens.css";
"use client";

import { useRouter } from "next/navigation";

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

export function Search() {
  const router = useRouter();
  return (
    <CommandPalette
      groups={[{ label: "DOCS", items: [{ value: "/docs/install", label: "Install" }] }]}
      onSelect={(href) => router.push(href)}
    />
  );
}

The trigger fits the actions slot of a Terminal Navbar. Mount one palette per page, because each one with shortcut on listens for ⌘K.

States

Accessibility