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.
Enrol a member Ctrl+E
View member directory
Submit a claim Ctrl+C
Review pending claims
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
| Property | Value |
|---|---|
| Surface | --popover fill, --radius-lg (8px) |
| Input row | 44px tall, 14px text, leading search glyph, 1px --border rule |
| List | Max height 320px, scrolls |
| Item | 14px text, 8px × 6px padding, highlight --accent |
| Group heading | 12px / Inter 600, --muted-foreground |
| Shortcut | 12px letter-spaced, --muted-foreground, right-aligned |
| Empty state | 14px --muted-foreground, centred |
| Dialog variant | Dialog 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
onSelectonce 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
⌘Kin the hint — use<Kbd mod>K</Kbd>, which follows the reader's platform. - Bind the launcher to
metaKeyalone — checke.metaKey || e.ctrlKeyso 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.
CommandSeparatoris hidden from assistive tech (aria-hidden) — it is decorative, and the grouping it suggests is already conveyed by eachCommandGroupheading.CommandDialogannounces its screen-reader-only title and description on open, and inheritsDialog's focus trap and focus return.
Every Command part and prop in Storybook
Tooltip
A small hint shown on hover or focus. Non-interactive by design — it cannot hold buttons or links, and its content must never be the only way to reach information.
Cookie banner
Consent notice shown on first visit. Stateless by design — wire the handlers to your consent store and unmount it once a choice is made.