Skip to main content

CommandPalette

ComplexNavigation<co-command-palette>

CommandPalette is the Command Bar style's "Jump to anything" search for screens, patients and actions, opened with Ctrl K or Cmd K.

import { CommandPalette } from 'health-components';

Examples​

Filtered​

Storybook

No Results​

Storybook

Open With Shortcut​

Storybook

Usage​

{open && <CommandPalette items={searchIndex} onSelect={go} onClose={() => setOpen(false)} />} // open on Ctrl K / Cmd K
const [open, setOpen] = useState(false);
useCommandPaletteShortcut(() => setOpen(true)); // Ctrl K / Cmd K
<CommandPalette open={open} items={searchIndex} onSelect={go} onClose={() => setOpen(false)} />

When to use​

  • Command Bar style, and as a shortcut in every style.

When not to use​

  • Patient search inside a form: Combobox.

Variants and states​

VariantWhat it is
resultsKind pill (Screen, Patient, Action), icon, label, meta.
active rowprimary-soft.
no resultsSuggests what to type.

Accessibility​

  • combobox with listbox; arrows, Enter, Escape. Key hints in the footer.

Do and don't​

  • Do: Return patients with DOB and MRN in meta.
  • Don't: Run destructive actions straight from the palette without a confirm.

Props​

PropTypeDefaultDescription
items *T[]—The search index. Required.
openbooleantrueWhether the palette is shown
querystringuncontrolledQuery (controlled)
defaultQuerystring""Initial query when uncontrolled
onQueryChange(query: string) => voidnoneCalled on every keystroke
placeholderstring"Jump to a screen, patient or action"Input placeholder and accessible name
onSelect(item: T) => voidnoneCalled with the chosen item (Enter or click)
onClose() => voidnoneCalled on Escape and a scrim press
maxResultsnumber9Most results shown
inlinebooleanfalseRender in place for docs: no portal, focus trap, scroll lock or Escape
refRef<HTMLDivElement>—

Also accepts native attributes, including defaultChecked, defaultValue, autoFocus, onChange, onInput, plus className and event handlers on the root element.

Angular, Vue and HTML​

Register the elements once (Angular guide), then use <co-command-palette>. Attributes take strings; arrays and objects are set as properties (Angular [prop], Vue :prop) or as JSON attributes. Callbacks are DOM events with the value in event.detail.

Angular template
<co-command-palette open query="…" [items]="items" (co-query-change)="onQueryChange($event.detail)"></co-command-palette>
KindNameDescription
property / JSON attributeitemsThe search index. Required.
attributeopenWhether the palette is shown; default true
attributequeryQuery (controlled); default uncontrolled
attributedefault-query / defaultQueryInitial query when uncontrolled; default ""
attributeplaceholderInput placeholder and accessible name; default "Jump to a screen, patient or action"
attributemax-results / maxResultsMost results shown; default 9
attributeinlineRender in place for docs: no portal, focus trap, scroll lock or Escape; default false
attributedefault-checked / defaultChecked
property / JSON attributedefault-value / defaultValue
attributeauto-focus / autoFocus
property / JSON attributeref
eventco-query-changeCalled on every keystroke; default none (React: onQueryChange)
eventco-selectCalled with the chosen item (Enter or click); default none (React: onSelect)
eventco-closeCalled on Escape and a scrim press; default none (React: onClose)
eventco-change (React: onChange)
eventco-input (React: onInput)