CommandPalette
| Prop | Type | Required | Local default |
|---|---|---|---|
items | readonly CommandItem[] | Yes | — |
open | boolean | Yes | — |
onOpenChange | (open: boolean) => void | Yes | — |
placeholder | string | undefined | No | — |
Find and run commands from a searchable keyboard dialog. Use it when an application has many actions that are difficult to reach through navigation alone.
Install this example’s dependencies, load the package stylesheet from Setup, and add Example CSS where shown. The snippet includes its local helpers.
bun add @kongmy-dev/sapphire-ui react react-dom radix-ui"use client";
import { useState } from "react";
import { Button } from "@kongmy-dev/sapphire-ui/button";
import { CommandPalette } from "@kongmy-dev/sapphire-ui/command-palette";
function CommandActions() {
const [open, setOpen] = useState(false);
const [selected, setSelected] = useState('No action');
return (
<div className="sp-cluster">
<Button onClick={() => setOpen(true)}>Search actions</Button>
<CommandPalette
placeholder="Find an action…"
items={[
{
id: 'save',
label: 'Save draft',
onSelect: () => setSelected('Draft saved'),
},
{
id: 'publish',
label: 'Publish document',
onSelect: () => setSelected('Document published'),
},
]}
open={open}
onOpenChange={setOpen}
/>
<output>{selected}</output>
</div>
);
}
export default CommandActions;Load these demo styles alongside the package stylesheet for the same layout and surfaces.
.docs-palette-stage {
position: relative;
height: 80vh;
overflow: hidden;
contain: layout paint;
background: var(--background);
border: var(--border-width) solid var(--border);
border-radius: var(--radius-md);
}
.docs-palette-stage :is(.sp-sheet, .sp-sheet-overlay) {
animation-duration: 0s;
}
Initial rendered HTML only. React handlers and portalled content require the JSX example; static HTML does not reproduce those interactions.
Generated from the current public TypeScript signatures, including composed behaviour props. “—” means no default is declared in the local signature; forwarded behaviour defaults are not inferred.
| Prop | Type | Required | Local default |
|---|---|---|---|
items | readonly CommandItem[] | Yes | — |
open | boolean | Yes | — |
onOpenChange | (open: boolean) => void | Yes | — |
placeholder | string | undefined | No | — |
Supporting type used by this API.
| Prop | Type | Required | Local default |
|---|---|---|---|
id | string | Yes | — |
label | string | Yes | — |
hint | string | undefined | No | — |
icon | ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | null | undefined | No | — |
onSelect | (query: string) => void | Yes | — |
bun add @kongmy-dev/sapphire-ui react react-dom radix-uiFor an app using package components throughout, load the full stylesheet once. Add this component import where you use it.
import "@kongmy-dev/sapphire-ui/sapphire.css";
import { CommandPalette } from "@kongmy-dev/sapphire-ui/command-palette";Mixing package and vendored components? Follow application setup.