SearchField & CommandPalette
A search box with a wobbly marker outline that boils while it has focus, grouped results on a taped sheet, highlighter matches and keycap shortcuts. The same field powers a ⌘K command palette.
Client componentWCAG AANew
Live example
import { CommandPalette, SearchField } from "@plop-ui/react";
<SearchField
label="Search the sketchbook"
shortcut="/"
groups={[sketches, boards, people]} // { id, label, items: [{ id, title, sub, meta, lead }] }
recentKey="recent-searches"
onSelect={(item) => open(item)}
/>
<CommandPalette groups={[pages, people]} emptyGroups={[actions]} onSelect={run} /> // ⌘K / Ctrl KChange every prop live in the playground.
Props
SearchField
| Prop | Type | Default | What it does |
|---|---|---|---|
| labelrequired | string | none | What you're searching, e.g. "Search components". Always read by screen readers. |
| className | string | none | Extra class on the outer wrapper. |
| defaultValue | string | "" | Uncontrolled initial text. |
| emptyGroups | SearchGroup[] | none | Shown when the box is empty and focused, e.g. quick actions. Recent searches come first. |
| filter | boolean | true | Filter groups by the typed text and cap each at limit. false shows groups as given. |
| focusOnMount | boolean | false | Focus the input as soon as it mounts (the palette does this when it opens). |
| groups | SearchGroup[] | none | What can be found. Filtered as you type (title, sub, meta and keywords); pass filter={false}
if you filter yourself, e.g. on a server. |
| hideLabel | boolean | false | Hide the label visually (it stays for screen readers). Use it in tight headers. |
| inline | boolean | false | Keeps the results sheet open inline and the text after a pick; the command palette uses it. |
| limit | number | 4 | Max results per group. |
| loading | boolean | false | Hop dots instead of the eraser while results load. |
| onSelect | (item: SearchItem, group: SearchGroup) => void | none | Picked with Enter or a click. |
| onValueChange | (value: string) => void | none | Called with the new text as you type, and with "" when the box is cleared or a result is picked. |
| placeholder | string | the label | Hint text in the empty box. |
| recentKey | string | none | Remember picks under this localStorage key and offer them as recent searches. |
| shortcut | string | none | A keycap hint, and the key that focuses the field from anywhere on the page. "/" is a good one. |
| size | "sm" | "md" | "lg" | none | sm for headers, md (default), lg for a page about finding things. |
| value | string | none | Controlled text in the box. |
CommandPalette
| Prop | Type | Default | What it does |
|---|---|---|---|
| groupsrequired | SearchGroup[] | none | What can be found while typing. |
| onSelectrequired | (item: SearchItem, group: SearchGroup) => void | none | Called with the picked item and its group, after the palette closes. |
| emptyGroups | SearchGroup[] | none | Shown before typing, e.g. quick actions. |
| label | string | "Type a command or search" | Accessible name of the dialog and its search field. |
| onOpenChange | (open: boolean) => void | none | Called with the new open state when the shortcut, Escape, the backdrop or a pick opens or closes it. |
| open | boolean | false | Controlled open state. Leave both out and the palette opens with the shortcut on its own. |
| placeholder | string | the label | Hint text in the empty box. |
| recentKey | string | none | Remember picks under this localStorage key and offer them as recent searches. |
| shortcut | boolean | true | Toggle with Cmd+K on a Mac, Ctrl+K elsewhere. |
Use it well
DoGroup results by kind and give each a lead (a face, a status dot, an icon) so people can scan without reading.
Don'tHide the only way to reach a page inside the palette. It's a shortcut, not the map.
Accessibility
- The input is a combobox: aria-expanded, aria-controls and aria-activedescendant follow the arrow keys.
- Enter opens the active (or first) result; Escape clears the text, then closes.
- The result count is announced in a polite live region; group headings are never focusable.
- The palette is a native <dialog>, so focus stays inside and Escape closes it.