Overlays
CommandPalette
Free29.7 KB gzippedA modal command menu: a search field over a filtered, grouped list of commands, opened with a global hotkey (Cmd/Ctrl+K by default).
Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · Keys: Ctrl+K, ⌘+K, Arrow Down and 8 more · Full report
Import
import { CommandPalette } from "@vjdesigns/vjdesigns-ui";
Importing only CommandPalette adds about 29.7 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.
Examples
Basic
Open it with the button or the hotkey (this one uses Ctrl/⌘ + J, since these docs use ⌘K for search). Type to filter; matching characters are highlighted. Items with to open a nested page.
Last command: Nothing yet
import { useState } from "react";
import {
Button,
CommandPalette,
FileIcon,
HomeIcon,
KbdShortcut,
MoonIcon,
SettingsIcon,
Stack,
SunIcon,
Text,
UsersIcon,
} from "@vjdesigns/vjdesigns-ui";
export function Basic() {
const [last, setLast] = useState("Nothing yet");
return (
<Stack gap={3} align="center">
<CommandPalette
hotkey="mod+j"
trigger={
<Button variant="outline" tone="neutral">
Commands <KbdShortcut keys={["mod", "J"]} size="sm" />
</Button>
}
>
<CommandPalette.Input />
<CommandPalette.List>
<CommandPalette.Group heading="Go to">
<CommandPalette.Item icon={<HomeIcon />} onSelect={() => setLast("Dashboard")}>
Dashboard
</CommandPalette.Item>
<CommandPalette.Item icon={<UsersIcon />} keywords={["people", "members"]} onSelect={() => setLast("Team")}>
Team
</CommandPalette.Item>
<CommandPalette.Item icon={<FileIcon />} shortcut={["G", "D"]} onSelect={() => setLast("Documents")}>
Documents
</CommandPalette.Item>
</CommandPalette.Group>
<CommandPalette.Separator />
<CommandPalette.Group heading="Settings">
<CommandPalette.Item icon={<SettingsIcon />} to="theme">
Change theme…
</CommandPalette.Item>
</CommandPalette.Group>
<CommandPalette.Page name="theme" title="Theme">
<CommandPalette.Item icon={<SunIcon />} onSelect={() => setLast("Light theme")}>
Light
</CommandPalette.Item>
<CommandPalette.Item icon={<MoonIcon />} onSelect={() => setLast("Dark theme")}>
Dark
</CommandPalette.Item>
</CommandPalette.Page>
<CommandPalette.Empty />
</CommandPalette.List>
</CommandPalette>
<Text size="sm" tone="muted">
Last command: {last}
</Text>
</Stack>
);
}
Accessibility
The palette is a named dialog with a search box and a listbox. Keyboard instructions are attached to the search box, the number of results is announced politely as you type, and focus returns to the trigger when it closes. loop lets the arrow keys wrap around.
Last action: Nothing yet
import { useState } from "react";
import {
Button,
CommandPalette,
FileIcon,
Stack,
Text,
UsersIcon,
} from "@vjdesigns/vjdesigns-ui";
export function Accessibility() {
const [last, setLast] = useState("Nothing yet");
return (
<Stack gap={3} align="center">
<CommandPalette
hotkey={false}
loop
label="Quick actions"
trigger={
<Button variant="outline" tone="neutral">
Quick actions
</Button>
}
>
<CommandPalette.Input placeholder="Search actions…" />
<CommandPalette.List label="Actions">
<CommandPalette.Item icon={<FileIcon />} onSelect={() => setLast("New document")}>
New document
</CommandPalette.Item>
<CommandPalette.Item icon={<UsersIcon />} onSelect={() => setLast("Invite a teammate")}>
Invite a teammate
</CommandPalette.Item>
<CommandPalette.Empty />
</CommandPalette.List>
</CommandPalette>
<Text size="sm" tone="muted" role="status">
Last action: {last}
</Text>
</Stack>
);
}
Groups and keywords
Group related commands under a heading, and add keywords so people find an item by the words they think of ("people" finds Team). An item's shortcut is shown beside it and read with its name.
import {
Button,
CommandPalette,
HomeIcon,
MoonIcon,
SunIcon,
UsersIcon,
} from "@vjdesigns/vjdesigns-ui";
export function GroupsAndKeywords() {
return (
<CommandPalette
hotkey={false}
trigger={
<Button variant="outline" tone="neutral">
Open palette
</Button>
}
>
<CommandPalette.Input />
<CommandPalette.List>
<CommandPalette.Group heading="Navigate">
<CommandPalette.Item icon={<HomeIcon />} shortcut={["G", "H"]}>
Home
</CommandPalette.Item>
<CommandPalette.Item icon={<UsersIcon />} keywords={["people", "members", "staff"]}>
Team
</CommandPalette.Item>
</CommandPalette.Group>
<CommandPalette.Separator />
<CommandPalette.Group heading="Appearance">
<CommandPalette.Item icon={<SunIcon />}>Light theme</CommandPalette.Item>
<CommandPalette.Item icon={<MoonIcon />}>Dark theme</CommandPalette.Item>
</CommandPalette.Group>
<CommandPalette.Empty />
</CommandPalette.List>
</CommandPalette>
);
}
Translated
The dialog's name, the placeholder, the keyboard instructions, the results announcement and the empty message come from the locale (German here). Item labels are your own text.
import {
Button,
CommandPalette,
HomeIcon,
SettingsIcon,
LocaleProvider,
} from "@vjdesigns/vjdesigns-ui";
import de from "@vjdesigns/vjdesigns-ui/locales/de";
export function Translated() {
return (
<LocaleProvider locale="de" messages={de}>
<CommandPalette
hotkey={false}
trigger={
<Button variant="outline" tone="neutral">
Befehle
</Button>
}
>
<CommandPalette.Input />
<CommandPalette.List>
<CommandPalette.Item icon={<HomeIcon />}>Startseite</CommandPalette.Item>
<CommandPalette.Item icon={<SettingsIcon />}>Einstellungen</CommandPalette.Item>
<CommandPalette.Empty />
</CommandPalette.List>
</CommandPalette>
</LocaleProvider>
);
}
Right to left
The first example again, inside a right-to-left LocaleProvider (Arabic). Layout, spacing and arrow icons mirror, and the components' built-in text is translated. The example's own text stays in English.
Basic
Last command: Nothing yet
import { LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";
// Basic is the "Basic" example above.
<LocaleProvider locale="ar" messages={ar}>
<Basic />
</LocaleProvider>
Usage notes
Compose it from CommandPalette.Input, CommandPalette.List, CommandPalette.Group, CommandPalette.Item, CommandPalette.Empty, CommandPalette.Loading, CommandPalette.Separator, and CommandPalette.Page. Items register themselves, so filtering and the keyboard order follow the rendered order (ranked by match while searching). Put items and groups directly inside the list, a group, or a page (components and fragments are fine; extra wrapper elements are not).
Built on Modal: the page is inert, scroll is locked, focus is trapped, and focus returns to the opener on close. Nested overlays work through the shared overlay layer stack.
Keyboard (focus stays in the search input; the active option is tracked with aria-activedescendant):
- Down / Up (and Ctrl+N / Ctrl+P): next / previous item, wrapping.
- PageDown / PageUp: move 10 items (stops at the ends).
- Home / End: move the text caret, as in any text field (APG editable combobox guidance), not the active item.
- Enter: run the active item, then close (key repeats are ignored).
- Escape: clears the search if there is any; otherwise goes back one page on a nested page; otherwise closes.
- Backspace in an empty search: go back one page.
API reference
CommandPalette
| Prop | Type | Default |
|---|---|---|
openWhether the palette is open (controlled). Pair with | boolean | — |
defaultOpenWhether the palette starts open (uncontrolled). | boolean | false |
onOpenChangeCalled with the next open state. | (open: boolean) => void | — |
hotkeyGlobal shortcut that toggles the palette, such as The listener ignores the key while another modal layer (Modal, Drawer, a second palette) is open on top, and while the user is typing in a text field, textarea, select, or contenteditable element, except the palette's own search input (so the shortcut also closes it). | string | false | "mod+k" |
triggerOptional element that opens the palette, usually a | ReactElement | — |
labelAccessible name of the dialog (visually hidden). Localize it here. | string | "Command palette" |
searchThe search text (controlled). Pair with | string | — |
defaultSearchInitial search text (uncontrolled). | string | "" |
onSearchChangeCalled with the search text as the user types. Use it to fetch server-driven results (with | (search: string) => void | — |
pagesStack of open page names, root first (controlled). See | string[] | — |
defaultPagesInitial page stack (uncontrolled). | string[] | [] |
onPagesChangeCalled with the next page stack when the user drills in or goes back. | (pages: string[]) => void | — |
filterCustom scoring: return | CommandPaletteFilter | — |
shouldFilterFilter and rank items against the search. Turn it off for server-driven results: every rendered item is shown, in order. | boolean | true |
sortRank matching items (and groups) by score while searching. Off keeps the rendered order. Ranking reorders the DOM so screen readers read results in ranked order; the list's children remount when ranking starts and stops, so keep item state outside the items. | boolean | true |
highlightMatchesMark the matched characters in plain-text item labels. | boolean | true |
closeOnSelectClose after an item's | boolean | true |
loopArrow keys wrap from the last item to the first and back. | boolean | true |
sizeWidth on screens 640px and wider: | "sm""md""lg" | "md" |
resultsLabelBuilds the polite results announcement. Localize it here. | (count: number) => string | "3 results" |
instructionsKeyboard instructions for screen readers, attached once to the search input with | string | — |
showHintsShow the keyboard hint row at the bottom (hidden from assistive tech and below 640px). | boolean | true |
hintLabelsText of the keyboard hint row. | CommandPaletteHintLabels | — |
backLabelAccessible name of the back button shown on nested pages. | string | "Back" |
children
| ReactNode | — |
Also accepts native <div> attributes, plus className, style and ref.
CommandPalette.Input
The search field: role="combobox" controlling the list, with aria-activedescendant pointing at the active option. It keeps DOM focus the whole time. Named by the palette's label (plus the current page title) unless you pass aria-label. On nested pages it also shows the page trail and a back button.
| Prop | Type | Default |
|---|---|---|
placeholderHint shown while the search is empty. Localize it here. | string | "Type a command or search…" |
Also accepts native <input> attributes, plus className, style and ref.
CommandPalette.List
The scrolling role="listbox". Put Group, Item, Separator, and Page inside. Empty and Loading can go here too: they render just after the listbox (not inside it), so the listbox only holds options and groups.
| Prop | Type | Default |
|---|---|---|
labelAccessible name of the listbox. Localize it here. | string | "Commands" |
Also accepts native <div> attributes, plus className, style and ref.
CommandPalette.Group
A labelled role="group" of items. It hides itself when none of its items match the search, and moves up while searching when it holds the best match.
| Prop | Type | Default |
|---|---|---|
headingVisible group label; names the | ReactNode | — |
Also accepts native <div> attributes, plus className, style and ref.
CommandPalette.Item
One command: role="option". Hidden when it doesn't match the search. Hovering makes it active only on real pointer movement, so a resting pointer doesn't fight the keyboard.
| Prop | Type | Default |
|---|---|---|
valueText the search matches against, and the value passed to | string | — |
keywordsExtra search terms (synonyms, ids) that match but aren't shown. | string[] | — |
childrenLabel. Plain-text labels get their matched characters highlighted. Defaults to | ReactNode | — |
iconDecorative icon before the label. Hidden from assistive technology. | ReactNode | — |
shortcutShortcut hint at the end of the row. | CommandPaletteShortcut | — |
onSelectRuns when the item is chosen with Enter or a click. The palette then closes, unless the handler calls | (event: CommandPaletteSelectEvent) => void | boolean | — |
toOpens the | string | — |
disabledShows the item as unavailable. It can still be reached with the arrow keys (so it's discoverable) but can't be run. | boolean | false |
Also accepts native <div> attributes, plus className, style and ref.
CommandPalette.Empty
Shown when nothing matches (and nothing is loading). Rendered just after the listbox. The result count is already announced by the palette, so this isn't a live region.
| Prop | Type | Default |
|---|---|---|
childrenCustom content. Defaults to a small "No results" | ReactNode | — |
Also accepts native <div> attributes, plus className, style and ref.
CommandPalette.Loading
Render while results are loading. It shows a spinner row after the listbox (role="status"), marks the listbox aria-busy, hides Empty, and holds the results announcement until loading ends.
| Prop | Type | Default |
|---|---|---|
childrenVisible (and announced) text. Localize it here. | ReactNode | "Loading results…" |
Also accepts native <div> attributes, plus className, style and ref.
CommandPalette.Separator
A decorative divider between items or groups. Hidden while searching.
Also accepts native <div> attributes, plus className, style and ref.
CommandPalette.Page
A nested list (e.g. "Change theme…"), shown instead of the root items while it is the current page. Opening a page clears the search; Back, Backspace in an empty search, or Escape goes back. Renders no element.
| Prop | Type | Default |
|---|---|---|
nameRequiredPage name. An item with | string | — |
titleRequiredTitle shown in the page trail and announced on entry. | string | — |
childrenThe page's items and groups. | ReactNode | — |
See what changed in each version in the Changelog.
Accessibility report
CommandPalette targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.
axe-core audit (live)
Checking the examples above…
Lighthouse audit
Light mode
Score 10035 passed · 0 failed · 30 not applicable · 10 to check by hand
Dark mode
Score 10035 passed · 0 failed · 30 not applicable · 10 to check by hand
Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.
Built-in behavior
Keyboard
| Key | Action |
|---|---|
| Ctrl+K⌘+K | Opens or closes the palette (hotkey). |
| Arrow DownArrow Up | Next or previous item, wrapping. Ctrl+N and Ctrl+P also work. |
| Page DownPage Up | Moves 10 items, stopping at the ends. |
| HomeEnd | Move the text caret in the search field. |
| Enter | Runs the active item, then closes. |
| Escape | Clears the search; otherwise goes back a page; otherwise closes. |
| Backspace | In an empty search: goes back a page. |
A modal dialog: focus stays in the search field (the active item is tracked with aria-activedescendant), the page is inert, and focus returns to the opener on close.
Roles and states
| Element | Role | States and properties |
|---|---|---|
| Dialog | dialog | aria-modal="true", aria-label |
| Search field | combobox | aria-haspopup="listbox", aria-expanded, aria-controls → list, aria-activedescendant, aria-autocomplete="list" |
| Results | listbox | Groups are group, items are option with aria-selected |
| Trigger | button | aria-haspopup="dialog", aria-expanded, aria-keyshortcuts |
| Result count | status | — |
Manual checks
Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck. | 2.1.1 (A), 2.1.2 (A) |
| Focus | Focus moves in a logical order, is always visible, and isn't hidden behind sticky headers. | 2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA) |
| Screen readers | Names, roles and states are announced correctly, and status changes are announced without moving focus. | 1.3.1 (A), 4.1.2 (A), 4.1.3 (AA) |
| Color | Meaning never depends on color alone; your own colors meet contrast in both modes. | 1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA) |
| Zoom and reflow | At 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed. | 1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA) |
| Pointer targets | Click and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap. | 2.5.8 (AA), 2.5.5 (AAA) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |