Navigation
Command palette
The ⌘K palette: a search box over a flat list of commands.
Client componentSource
Import
import { CommandPalette } from '@the_viveksingh/vivek-ui'Ctrl+K search
A modal combobox: the hotkey is bound for you, filtering is over label plus keywords, and arrows move aria-activedescendant rather than DOM focus, so the query box keeps the caret.
Or press Ctrl K
const [open, setOpen] = useState(false)
<CommandPalette
open={open}
onOpenChange={setOpen}
placeholder="Search components, charts and pages"
items={[
{
heading: 'Navigate',
items: [
{ id: 'overview', label: 'Overview', keywords: ['start', 'install'] },
{ id: 'button', label: 'Button', description: 'Component' },
],
},
{
heading: 'Actions',
items: [
{ id: 'theme', label: 'Toggle dark mode', shortcut: 'T' },
{ id: 'copy', label: 'Copy install command', shortcut: 'C' },
],
},
]}
onSelect={(item) => run(item.id)}
/>Props
Generated from the package's own type declarations, so this table cannot drift from the code.
| Prop | Type | Default | Description |
|---|---|---|---|
open | boolean | — | Controlled open state. |
defaultOpen | boolean | — | Initial open state while uncontrolled. Default `false`. |
onOpenChange | (open: boolean) => void | — | — |
items | ReadonlyArray<CommandPaletteEntry> | — | Commands, grouped or loose. |
placeholder | string | — | — |
onSelect | (item: CommandPaletteItem) => void | — | Called with the chosen command. The palette closes afterwards. |
emptyState | ReactNode | — | Shown when nothing matches. Default `"No results found."`. |
hotkey | string | null | — | Global shortcut that toggles the palette. `mod` resolves to Command on Apple platforms and Control elsewhere. `null` turns the listener off. Default `'mod+k'`. |
query | string | — | Controlled search text. |
defaultQuery | string | — | Initial search text while uncontrolled. Default `''`. |
onQueryChange | (query: string) => void | — | — |
filter | (item: CommandPaletteItem, query: string) => boolean | — | Replaces the built-in matcher — pass one that always returns `true` for async search. |
label | string | — | Accessible name for the dialog and the search box. Default `"Command palette"`. |
resultsLabel | string | — | Accessible name for the results list. Default `"Results"`. |
size | ModalSize | — | Dialog width. Default `lg`. |
container | PortalContainer | — | Portal mount point. Defaults to `document.body`. |
footer | ReactNode | — | A hint bar under the results — key legends, a count. |
id | string | — | Id root for the combobox/listbox/option wiring. Generated when omitted. |
className | string | — | — |
Rendering
Client component
CommandPalette declares 'use client' because it needs state, effects or event handlers. Importing it into a Server Component creates a client boundary at this component — everything above it stays on the server.