Skip to content
MIZU.

CommandPalette

Search commands and execute them without taking your hands off the keyboard.

View .md

Live — this one is real

Choose a command.

Usage

tsx
"use client";

import { useState } from "react";
import { CommandPalette, Button } from "mizu-ui";

export function Example() {
  const [open, setOpen] = useState(false),
    [result, setResult] = useState("Choose a command.");
  return (
    <div>
      <Button onClick={() => setOpen(true)}>Open commands</Button>
      <p role="status" className="mizu-field-hint">
        {result}
      </p>
      <CommandPalette
        open={open}
        onOpenChange={setOpen}
        commands={[
          {
            id: "new",
            label: "Create a draft",
            description: "Start a new local record",
            onSelect: () => setResult("Draft created."),
          },
          {
            id: "review",
            label: "Review the release",
            description: "Open the review queue",
            onSelect: () => setResult("Review queue opened."),
          },
          {
            id: "save",
            label: "Save changes",
            shortcut: "⌘ S",
            onSelect: () => setResult("Changes saved."),
          },
        ]}
      />
    </div>
  );
}

It starts with "use client" because it keeps state or passes functions to components, so it pastes into a Next.js page as it is. Other React setups ignore the directive.

Source & setup

Add this component to your project with the shadcn CLI. The command copies its source into your configured UI directory, with base.css, Mizu’s tokens, and the stylesheets that hold its rules. Each rule lives in one stylesheet, so components you add together never repeat CSS. In a project without a components.json, run npx shadcn@latest init 0xuser64bit/mizu/preset first: plain init installs shadcn’s theme into your global CSS. Then load the fonts.

sh
npx shadcn@latest add 0xuser64bit/mizu/command-palette 0xuser64bit/mizu/button

The example also uses Button, so the command adds it too.

Every component imports from its own path, its name in kebab case. To paste the example, replace its mizu-ui import with:

tsx
import { CommandPalette } from "@/components/ui/mizu/command-palette";
import { Button } from "@/components/ui/mizu/button";

For npm imports, import mizu-ui/styles.css once. Fonts are optional via mizu-ui/fonts.css. Override --mizu-* tokens or use className for local styling. Uses native React and CSS; install the package peers for root imports. A Client Component: its source starts with “use client”.

Inspect navigation/CommandPalette.tsx

Source is included in the npm package under src/navigation/CommandPalette.tsx.

Open full source ↗

Props

PropTypeDefaultDescription
open / onOpenChangeboolean / function—Controlled modal visibility.
commandsCommand[]—Stable id, label, description, optional shortcut/disabled and onSelect. Optional keywords are matched but not shown, for other names people search by.
label / placeholderstring—Accessible name and search prompt.

Accessibility

Native modal contains focus and restores its trigger. Combobox/listbox exposes active commands. Up/down wraps, Enter executes; Escape closes.

Motion

Modal entrance obeys reduced motion.

Works alongside