CommandPalette
Search commands and execute them without taking your hands off the keyboard.
Live — this one is real
Choose a command.
Usage
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>
);
}
Source & setup
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.
Inspect navigation/CommandPalette.tsx
Source is included in the npm package under src/navigation/CommandPalette.tsx.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| open / onOpenChange | boolean / function | — | Controlled modal visibility. |
| commands | Command[] | — | Stable id, label, description, optional shortcut/disabled and onSelect. |
| label / placeholder | string | — | 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.