Design System
Overlays

Command

A searchable command palette for finding and running actions from the keyboard. Group results by area and show the shortcut alongside anything that has one.

Purpose

The palette is for people who know what they want to do and would rather type it than navigate to it. It complements the sidebar; it does not replace it.

Palette

The inline form below embeds the palette in the page. CommandEmpty renders whenever the query matches nothing — always include it, because a silent palette reads as broken. Clear the search in the preview and type nonsense to see it.

Command dialog (⌘K / Ctrl+K)

For the launcher pattern, wrap the same parts in CommandDialog — a Dialog that supplies a screen-reader-only title and description (defaults "Command palette" and "Search for a command"; override with its title and description props). It takes every Dialog prop, so open / onOpenChange wire it to a global shortcut. The listener needs state, so compose it in your own component:

import * as React from "react";
import {
  CommandDialog,
  CommandInput,
  CommandList,
  CommandEmpty,
  CommandGroup,
  CommandItem,
} from "@healthmetrics/ui/command";

function CommandLauncher() {
  const [open, setOpen] = React.useState(false);

  React.useEffect(() => {
    const down = (e: KeyboardEvent) => {
      if (e.key === "k" && (e.metaKey || e.ctrlKey)) {
        e.preventDefault();
        setOpen((open) => !open);
      }
    };
    document.addEventListener("keydown", down);
    return () => document.removeEventListener("keydown", down);
  }, []);

  return (
    <CommandDialog open={open} onOpenChange={setOpen}>
      <CommandInput placeholder="Type a command or search…" />
      <CommandList>
        <CommandEmpty>No results found.</CommandEmpty>
        <CommandGroup heading="Members">
          <CommandItem onSelect={() => setOpen(false)}>Enrol a member</CommandItem>
        </CommandGroup>
      </CommandList>
    </CommandDialog>
  );
}

Structure

PropertyValue
Surface--popover fill, --radius-lg (8px)
Input row44px tall, 14px text, leading search glyph, 1px --border rule
ListMax height 320px, scrolls
Item14px text, 8px × 6px padding, highlight --accent
Group heading12px / Inter 600, --muted-foreground
Shortcut12px letter-spaced, --muted-foreground, right-aligned
Empty state14px --muted-foreground, centred
Dialog variantDialog surface at max 512px, palette padding stripped (p-0)

Best practices

Do

  • Always render a CommandEmpty — a palette with no feedback reads as broken.
  • Group by area and show shortcuts where they exist.
  • Close the dialog in onSelect once the item's action has run.

Don't

  • Make the palette the only route to an action.
  • List every action in the product; rank by what people actually do.
  • Hard-code ⌘K in the hint — use <Kbd mod>K</Kbd>, which follows the reader's platform.
  • Bind the launcher to metaKey alone — check e.metaKey || e.ctrlKey so it works on Windows too.

Accessibility & keyboard

  • Keyboard: type to filter; arrow keys move; Enter runs the highlighted item; Esc closes.
  • The list is a listbox, and the highlighted option is announced as you move.
  • CommandSeparator is hidden from assistive tech (aria-hidden) — it is decorative, and the grouping it suggests is already conveyed by each CommandGroup heading.
  • CommandDialog announces its screen-reader-only title and description on open, and inherits Dialog's focus trap and focus return.

Every Command part and prop in Storybook

On this page