Skip to content
Vertical Jump Designs-uiFront-End Studio
Get Pro

v3.9 is out.

Overlays

CommandPalette

Free29.7 KB gzipped

A 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

tsx
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

tsx
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

tsx
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.

tsx
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.

tsx
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

tsx
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

CommandPalette props
PropTypeDefault
open

Whether the palette is open (controlled). Pair with onOpenChange.

boolean—
defaultOpen

Whether the palette starts open (uncontrolled).

booleanfalse
onOpenChange

Called with the next open state.

(open: boolean) => void—
hotkey

Global shortcut that toggles the palette, such as "mod+k" (mod is Cmd on Mac and Ctrl elsewhere), "shift+mod+p", or "ctrl+/". Pass false to turn it off.

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"
trigger

Optional element that opens the palette, usually a Button. It gets aria-haspopup="dialog", aria-expanded, and aria-keyshortcuts for the hotkey, and focus returns to it on close.

ReactElement—
label

Accessible name of the dialog (visually hidden). Localize it here.

string"Command palette"
search

The search text (controlled). Pair with onSearchChange.

string—
defaultSearch

Initial search text (uncontrolled).

string""
onSearchChange

Called with the search text as the user types. Use it to fetch server-driven results (with shouldFilter={false}). The search is cleared (with a call to this) each time the palette finishes closing.

(search: string) => void—
pages

Stack of open page names, root first (controlled). See CommandPalette.Page.

string[]—
defaultPages

Initial page stack (uncontrolled).

string[][]
onPagesChange

Called with the next page stack when the user drills in or goes back.

(pages: string[]) => void—
filter

Custom scoring: return 0 to hide an item and higher numbers to rank it first. Defaults to a fuzzy, case- and diacritic-insensitive match on the item's value and keywords (see defaultCommandScore).

CommandPaletteFilter—
shouldFilter

Filter and rank items against the search. Turn it off for server-driven results: every rendered item is shown, in order.

booleantrue
sort

Rank 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.

booleantrue
highlightMatches

Mark the matched characters in plain-text item labels.

booleantrue
closeOnSelect

Close after an item's onSelect runs. An item can still keep the palette open with event.preventDefault() or by returning false.

booleantrue
loop

Arrow keys wrap from the last item to the first and back.

booleantrue
size

Width on screens 640px and wider: sm 30rem, md 40rem, lg 48rem.

"sm""md""lg""md"
resultsLabel

Builds the polite results announcement. Localize it here.

(count: number) => string"3 results"
instructions

Keyboard instructions for screen readers, attached once to the search input with aria-describedby. Localize it here.

string—
showHints

Show the keyboard hint row at the bottom (hidden from assistive tech and below 640px).

booleantrue
hintLabels

Text of the keyboard hint row.

CommandPaletteHintLabels—
backLabel

Accessible name of the back button shown on nested pages.

string"Back"
children

CommandPalette.Input, CommandPalette.List and its contents.

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.

CommandPalette.Input props
PropTypeDefault
placeholder

Hint 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.

CommandPalette.List props
PropTypeDefault
label

Accessible 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.

CommandPalette.Group props
PropTypeDefault
heading

Visible group label; names the role="group". Without it, pass aria-label.

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.

CommandPalette.Item props
PropTypeDefault
value

Text the search matches against, and the value passed to onSelect. Defaults to children when that is a string; required otherwise.

string—
keywords

Extra search terms (synonyms, ids) that match but aren't shown.

string[]—
children

Label. Plain-text labels get their matched characters highlighted. Defaults to value.

ReactNode—
icon

Decorative icon before the label. Hidden from assistive technology.

ReactNode—
shortcut

Shortcut hint at the end of the row.

CommandPaletteShortcut—
onSelect

Runs when the item is chosen with Enter or a click. The palette then closes, unless the handler calls event.preventDefault() or returns false (or the palette has closeOnSelect={false}).

(event: CommandPaletteSelectEvent) => void | boolean—
to

Opens the CommandPalette.Page with this name instead of running a command. Shows a chevron. End the label with "…" by convention.

string—
disabled

Shows the item as unavailable. It can still be reached with the arrow keys (so it's discoverable) but can't be run.

booleanfalse

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.

CommandPalette.Empty props
PropTypeDefault
children

Custom content. Defaults to a small "No results" EmptyState naming the search.

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.

CommandPalette.Loading props
PropTypeDefault
children

Visible (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.

CommandPalette.Page props
PropTypeDefault
nameRequired

Page name. An item with to={name} opens it.

string—
titleRequired

Title shown in the page trail and announced on entry.

string—
children

The 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)

Running accessibility audit

Checking the examples above…

Lighthouse audit

Light mode

Score 100

35 passed · 0 failed · 30 not applicable · 10 to check by hand

Dark mode

Score 100

35 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

Keyboard
KeyAction
Ctrl+K⌘+KOpens or closes the palette (hotkey).
Arrow DownArrow UpNext or previous item, wrapping. Ctrl+N and Ctrl+P also work.
Page DownPage UpMoves 10 items, stopping at the ends.
HomeEndMove the text caret in the search field.
EnterRuns the active item, then closes.
EscapeClears the search; otherwise goes back a page; otherwise closes.
BackspaceIn 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

Roles and states
ElementRoleStates and properties
Dialogdialogaria-modal="true", aria-label
Search fieldcomboboxaria-haspopup="listbox", aria-expanded, aria-controls → list, aria-activedescendant, aria-autocomplete="list"
ResultslistboxGroups are group, items are option with aria-selected
Triggerbuttonaria-haspopup="dialog", aria-expanded, aria-keyshortcuts
Result countstatus—

Manual checks

Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.

Manual accessibility checks
CheckWhat to testWCAG 2.2
KeyboardEvery 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)
FocusFocus 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 readersNames, 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)
ColorMeaning 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 reflowAt 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 targetsClick 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)
MotionAnimations respect the reduced-motion setting.2.3.3 (AAA)