Vesture

Overlays

CommandPalette

A Cmd+K style global command launcher — a centered search input over a filtered, keyboard-navigable, optionally grouped and virtualized list of commands.

CommandPaletteuseCommandPaletteShortcut

Preview

Usage

tsx
import { CommandPalette, useCommandPaletteShortcut } from "@vesture/react";

function Example() {
  const [open, setOpen] = useState(false);
  useCommandPaletteShortcut(setOpen);

  return (
    <CommandPalette
      open={open}
      onOpenChange={setOpen}
      commands={[
        { id: "new-file", label: "New File", group: "File", shortcut: "⌘N", onSelect: () => createFile() },
        { id: "toggle-theme", label: "Toggle Theme", group: "View", keywords: ["dark", "light"], onSelect: () => toggleTheme() },
      ]}
    />
  );
}

Behavior

  • Fully controlled (open/onOpenChange), same shape as Modal — renders via FloatingPortal + FloatingOverlay (locks scroll) + a non-modal FloatingFocusManager that autofocuses the search input.
  • Filters commands client-side by default (case-insensitive substring against label + keywords + group); pass filterCommands to override, e.g. for fuzzy matching.
  • ArrowUp/ArrowDown move the highlighted command (skipping disabled ones, looping at the ends), Enter runs the active command's onSelect and closes, Escape closes without selecting.
  • Commands with a group render under a section header, ordered by each group's first appearance in the commands array; headers are non-interactive and skipped by keyboard nav, and only appear for groups with at least one match after filtering.
  • Long lists switch to windowed rendering once row count reaches virtualizationThreshold (default 50) — the same manual scrollTop-based approach as Combobox and DataGrid, not an external virtualization dependency.
  • useCommandPaletteShortcut is a separate opt-in hook — CommandPalette itself has no baked-in global shortcut. It binds Cmd+K on Mac / Ctrl+K elsewhere by default (checks navigator.platform), attaches a document-level keydown listener, and cleans up on unmount.

Props

CommandItem

PropTypeDefaultDescription
idstringRequired. Stable identity, used for React keys and aria ids.
labelstringRequired. Displayed text, matched by the default filter.
descriptionstringOptional secondary line shown under the label.
iconReactNodeOptional leading icon.
keywordsstring[]Extra searchable terms not shown in the label.
shortcutstringDisplay-only, e.g. "⌘K".
groupstringGroups render under a section header, ordered by first appearance.
onSelect() => voidRequired. Fires on Enter or click, then the palette closes.
disabledbooleanSkipped by keyboard nav and unclickable.

CommandPalette

PropTypeDefaultDescription
openbooleanRequired. Controls visibility.
onOpenChange(open: boolean) => voidRequired. Fires on dismiss/select requests.
commandsCommandItem[]Required.
placeholderstring"Type a command or search..."Search input placeholder.
emptyMessagestring"No matching commands"Shown when filtering matches nothing.
filterCommands(commands, query) => CommandItem[]Overrides the default substring filter.
virtualizationThresholdnumber50Row count (commands + group headers) at/above which the list windows its rendering.

useCommandPaletteShortcut(onOpenChange, options?)

PropTypeDefaultDescription
keystring"k"Key to match, case-insensitive.
metaKey / ctrlKeybooleanOverride the platform default (Cmd on Mac, Ctrl elsewhere).