Command Palette

The Command Palette component allows users to quickly find and execute commands via keyboard navigation or search, with optional async search support.

Usage

Default

<CommandPalette 
  isOpen={isOpen}
  onClose={() => setIsOpen(false)}
  commands={[
    { label: "Open Dashboard", action: () => alert("Dashboard opened") },
    { label: "View Settings", action: () => alert("Settings opened") },
    { label: "Log Out", action: () => alert("Logged out") },
  ]}
/>

Props

Data table
TypeDescription
asyncSearch((query: string) => Promise<CommandItem[]>)Callback to handle the search input asynchronously.
classNamestringCustom classname for the command palette.
commandsCommandItem[]Array of available command options.
data-testidstringOptional test ID for testing frameworks.
debounceMsnumberOptional debounce time (in ms) for the search input.
emptyMessagestringMessage announced when there are no matching commands.
inputAriaDescribedBystringAccessible description reference for the search input.
inputAriaLabelstringAccessible label for the search input.
inputAriaLabelledBystringAccessible label reference for the search input.
inputIdstringOptional ID for the input element.
inputLabelstringOptional visible or screen-reader-only label for the input.
isOpenbooleanWhether the command palette is currently open.
listAriaLabelstringAccessible label for the command results list.
listboxIdstringOptional ID for the listbox element.
modalbooleanWhether the palette should behave like a modal dialog for assistive tech.
onClose() => voidCallback to close the command palette.
paletteIdstringOptional ID for the palette container/dialog.
placeholderstringOptional placeholder for the input field.
restoreFocusOnClosebooleanWhether focus should return to the trigger element on close.
resultsAnnouncementstringAccessible live region message prefix for result count updates.
roundingRoundingTypeRounding style for the palette ('none' | 'small' | 'medium' | 'large' | 'full').
shadowShadowTypeShadow style for the palette ('none' | 'light' | 'medium' | 'strong' | 'intense').
stateStateTypeThe state of the command palette ('success' | 'error' | 'warning' | 'disabled' | '').
themeThemeTypeTheme style for the palette ('primary' | 'secondary' | 'tertiary' | 'quaternary' | 'clear').
trapFocusbooleanWhether focus should be trapped while the palette is open.