Command
A search field over a list of actions or choices. Type to filter, move with the arrow keys, and press Enter to choose. Put it inline, inside a popover picker, or in a command palette dialog.
Installation
pnpm dlx shadcn@latest add https://sprout.tulipfarm.ai/r/command.jsonCopies Command and the components it uses (Dialog) into your app, installs the packages, and adds the styles. Then import it from @/components/ui/command. Needs Tailwind CSS 4 and a components.json from shadcn init.
Install the following dependencies:
pnpm add clsx tailwind-merge @hugeicons/core-free-icons @hugeicons/reactAdd Sprout base once per app: the
cn()helper and the design tokens.lib/sprout/classes.ts- Design tokens, for your global CSS
Add the components it uses: Dialog.
Copy and paste the following code into your project.
'use client'; import { createContext, isValidElement, useContext, useId, useLayoutEffect, useRef, useState, useSyncExternalStore, type ChangeEvent, type ComponentProps, type KeyboardEvent, type ReactNode, } from 'react'; import { CheckIcon } from '@/lib/sprout/icons/check-icon'; import { SearchIcon } from '@/lib/sprout/icons/search-icon'; import { cn } from '@/lib/sprout/classes'; import { Dialog, DialogContent, DialogDescription, DialogTitle, type DialogContentProps, type DialogProps, } from '@/components/ui/dialog'; export type CommandFilter = (value: string, search: string, keywords?: readonly string[]) => number; const normalize = (text: string) => text .normalize('NFD') .replace(/\p{Diacritic}/gu, '') .toLowerCase(); function tokenScore(haystack: string, token: string) { const index = haystack.indexOf(token); if (index === 0) return 1; if (index > 0) return /[\s\-_/.(]/.test(haystack[index - 1]!) ? 0.9 : 0.7; let from = 0; let last = -1; let gaps = 0; for (const char of token) { const found = haystack.indexOf(char, from); if (found === -1) return 0; if (last >= 0) gaps += found - last - 1; last = found; from = found + 1; } return Math.max(0.05, 0.5 - gaps * 0.02); } export const defaultCommandFilter: CommandFilter = (value, search, keywords = []) => { const haystack = normalize([value, ...keywords].join(' ')); const tokens = normalize(search).trim().split(/\s+/).filter(Boolean); let score = 1; for (const token of tokens) score = Math.min(score, tokenScore(haystack, token)); return score; }; interface Entry { value: string; keywords: readonly string[]; group: string | null; select: () => void; } interface Options { filter: CommandFilter; shouldFilter: boolean; } class CommandStore { search = ''; active: string | null = null; ready = false; count = 0; version = 0; needsFirst = true; options: Options = { filter: defaultCommandFilter, shouldFilter: true }; readonly items = new Map<string, Entry>(); readonly scores = new Map<string, number>(); readonly groupScores = new Map<string, number>(); private readonly listeners = new Set<() => void>(); private scheduled = false; subscribe = (listener: () => void) => { this.listeners.add(listener); return () => this.listeners.delete(listener); }; get filtering() { return this.options.shouldFilter && this.search.trim() !== ''; } emit() { this.version++; for (const listener of this.listeners) listener(); } refilter() { this.scores.clear(); this.groupScores.clear(); let count = 0; for (const [id, entry] of this.items) { const score = this.filtering ? this.options.filter(entry.value, this.search, entry.keywords) : 1; if (score <= 0) continue; count++; this.scores.set(id, score); if (entry.group) this.groupScores.set(entry.group, Math.max(score, this.groupScores.get(entry.group) ?? 0)); } this.count = count; } schedule() { if (this.scheduled) return; this.scheduled = true; queueMicrotask(() => { this.scheduled = false; this.refilter(); if (this.active && !this.scores.has(this.active)) this.needsFirst = true; this.emit(); }); } setSearch(search: string) { if (search === this.search) return; this.search = search; this.refilter(); this.needsFirst = true; this.emit(); } setActive(id: string | null) { if (id === this.active) return; this.active = id; this.emit(); } isVisible(id: string) { return !this.filtering || this.scores.has(id); } order(score: number | undefined) { return this.filtering && score ? -Math.round(score * 1000) : undefined; } } interface CommandContextValue { store: CommandStore; listId: string; inputId: string; labelId: string; label: string | undefined; } const CommandContext = createContext<CommandContextValue | null>(null); const GroupContext = createContext<string | null>(null); function useCommandContext(part: string) { const context = useContext(CommandContext); if (!context) throw new Error(`${part} must be inside Command.`); return context; } function useStore<T>(store: CommandStore, read: () => T) { return useSyncExternalStore(store.subscribe, read, read); } const ITEM = '[data-slot="command-item"]'; function orderOf(element: Element | null) { return element instanceof HTMLElement ? Number(element.style.order || 0) : 0; } function enabledItems(root: HTMLElement) { const items = [...root.querySelectorAll<HTMLElement>(`${ITEM}:not([aria-disabled="true"])`)].filter( item => item.closest('[data-slot="command"]') === root, ); const keyed = items.map(item => { const group = item.closest<HTMLElement>('[data-slot="command-group"]'); return group && root.contains(group) ? { item, group, outer: orderOf(group), inner: orderOf(item) } : { item, group: null, outer: orderOf(item), inner: 0 }; }); return keyed.sort((a, b) => a.outer - b.outer || a.inner - b.inner); } export interface CommandProps extends ComponentProps<'div'> { label?: string; shouldFilter?: boolean; filter?: CommandFilter; loop?: boolean; } export function Command({ label, shouldFilter = true, filter = defaultCommandFilter, loop = false, className, children, onKeyDown, ref, ...props }: CommandProps) { const [store] = useState(() => new CommandStore()); const root = useRef<HTMLDivElement | null>(null); const id = useId(); const context = useRef<CommandContextValue>({ store, listId: `${id}-list`, inputId: `${id}-input`, labelId: `${id}-label`, label, }).current; context.label = label; const version = useStore(store, () => store.version); useLayoutEffect(() => { const changed = store.options.filter !== filter || store.options.shouldFilter !== shouldFilter; store.options = { filter, shouldFilter }; if (changed && store.ready) { store.refilter(); store.needsFirst = true; store.emit(); } }, [store, filter, shouldFilter]); useLayoutEffect(() => { if (!store.ready) { store.ready = true; store.refilter(); store.emit(); return; } if (!store.needsFirst || !root.current) return; store.needsFirst = false; const first = enabledItems(root.current)[0]?.item; store.setActive(first?.id ?? null); root.current.querySelector('[data-slot="command-list"]')?.scrollTo({ top: 0 }); }, [store, version]); const move = (to: (items: ReturnType<typeof enabledItems>, index: number) => number) => { if (!root.current) return; const items = enabledItems(root.current); if (!items.length) return; const index = items.findIndex(({ item }) => item.id === store.active); const next = items[to(items, index)]; if (!next) return; store.setActive(next.item.id); const firstInGroup = next.group && items.find(({ group }) => group === next.group) === next; const heading = firstInGroup ? next.group!.querySelector('[data-slot="command-group-heading"]') : null; (heading ?? next.item).scrollIntoView({ block: 'nearest' }); if (heading) next.item.scrollIntoView({ block: 'nearest' }); }; const step = (delta: 1 | -1) => move((items, index) => { if (index === -1) return delta === 1 ? 0 : items.length - 1; const next = index + delta; if (loop) return (next + items.length) % items.length; return Math.min(Math.max(next, 0), items.length - 1); }); const jumpGroup = (delta: 1 | -1) => move((items, index) => { const current = items[index]; if (!current) return 0; const groups = [...new Set(items.map(({ group }) => group))]; const next = groups[groups.indexOf(current.group) + delta]; if (next === undefined) return index; return items.findIndex(({ group }) => group === next); }); const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => { onKeyDown?.(event); if (event.defaultPrevented || event.nativeEvent.isComposing) return; const target = event.target as HTMLElement; const fromInput = target.dataset.slot === 'command-input'; if (!fromInput && target.closest('button, a[href], input, textarea, select, [contenteditable]')) return; const vim = event.ctrlKey && !event.metaKey && !event.altKey; switch (event.key) { case 'ArrowDown': case 'ArrowUp': { const delta = event.key === 'ArrowDown' ? 1 : -1; if (event.metaKey) move(items => (delta === 1 ? items.length - 1 : 0)); else if (event.altKey) jumpGroup(delta); else step(delta); break; } case 'n': case 'j': if (!vim) return; step(1); break; case 'p': case 'k': if (!vim) return; step(-1); break; case 'Home': move(() => 0); break; case 'End': move(items => items.length - 1); break; case 'Enter': { if (!store.active) return; const entry = store.items.get(store.active); if (!entry) return; event.preventDefault(); entry.select(); return; } default: return; } event.preventDefault(); }; return ( <CommandContext.Provider value={context}> <div data-slot="command" {...props} ref={node => { root.current = node; if (typeof ref === 'function') return ref(node); if (ref) ref.current = node; }} className={cn('sprout-command', className)} onKeyDown={handleKeyDown} > {label && ( <label id={context.labelId} htmlFor={context.inputId} className="sprout-command-sr-only"> {label} </label> )} {children} </div> </CommandContext.Provider> ); } export interface CommandInputProps extends Omit< ComponentProps<'input'>, 'value' | 'defaultValue' | 'onChange' | 'type' > { value?: string; onValueChange?: (search: string) => void; onChange?: (event: ChangeEvent<HTMLInputElement>) => void; } export function CommandInput({ value, onValueChange, onChange, className, id, ...props }: CommandInputProps) { const { store, listId, inputId, labelId, label } = useCommandContext('CommandInput'); const search = useStore(store, () => store.search); const active = useStore(store, () => store.active); const empty = useStore(store, () => store.ready && store.count === 0); useLayoutEffect(() => { if (value !== undefined) store.setSearch(value); }, [store, value]); return ( <div data-slot="command-input-wrapper" className="sprout-command-input-wrapper"> <div data-slot="command-input-group" className="sprout-command-input-group"> <SearchIcon size="md" aria-hidden="true" className="sprout-command-input-icon" /> <input id={id ?? inputId} type="text" role="combobox" autoComplete="off" autoCorrect="off" spellCheck={false} aria-autocomplete="list" aria-expanded={!empty} aria-controls={listId} aria-labelledby={label && !props['aria-label'] ? labelId : undefined} aria-activedescendant={active ?? undefined} data-slot="command-input" {...props} value={value ?? search} onChange={event => { onChange?.(event); onValueChange?.(event.target.value); if (value === undefined) store.setSearch(event.target.value); }} className={cn('sprout-command-input', className)} /> </div> </div> ); } export type CommandListProps = ComponentProps<'div'>; export function CommandList({ className, children, ...props }: CommandListProps) { const { store, listId, label } = useCommandContext('CommandList'); const empty = useStore(store, () => store.ready && store.count === 0); const { 'aria-label': ariaLabel = props['aria-labelledby'] ? undefined : (label ?? 'Suggestions'), 'aria-labelledby': ariaLabelledBy, ...rest } = props; return ( <div id={listId} role={empty ? undefined : 'listbox'} tabIndex={empty ? undefined : -1} aria-label={empty ? undefined : ariaLabel} aria-labelledby={empty ? undefined : ariaLabelledBy} data-slot="command-list" data-empty={empty || undefined} {...rest} className={cn('sprout-command-list', className)} > <div data-slot="command-list-sizer" className="sprout-command-list-sizer"> {children} </div> </div> ); } export type CommandEmptyProps = ComponentProps<'div'>; export function CommandEmpty({ className, ...props }: CommandEmptyProps) { const { store } = useCommandContext('CommandEmpty'); const empty = useStore(store, () => store.ready && store.count === 0); if (!empty) return null; return ( <div role="presentation" data-slot="command-empty" {...props} className={cn('sprout-command-empty', className)} /> ); } export interface CommandGroupProps extends Omit<ComponentProps<'div'>, 'value'> { heading?: ReactNode; forceMount?: boolean; } export function CommandGroup({ heading, forceMount = false, className, children, style, ...props }: CommandGroupProps) { const { store } = useCommandContext('CommandGroup'); const id = useId(); const headingId = `${id}-heading`; const matched = useStore(store, () => store.groupScores.has(id)); const filtering = useStore(store, () => store.filtering); const order = useStore(store, () => store.order(store.groupScores.get(id))); const hidden = filtering && !matched && !forceMount; return ( <div role="presentation" data-slot="command-group" hidden={hidden || undefined} {...props} style={{ order, ...style }} className={cn('sprout-command-group', className)} > {heading != null && heading !== false && ( <div id={headingId} aria-hidden="true" data-slot="command-group-heading" className="sprout-command-group-heading" > {heading} </div> )} <div role="group" aria-labelledby={heading != null && heading !== false ? headingId : undefined} data-slot="command-group-items" className="sprout-command-group-items" > <GroupContext.Provider value={id}>{children}</GroupContext.Provider> </div> </div> ); } export interface CommandSeparatorProps extends ComponentProps<'div'> { alwaysRender?: boolean; } export function CommandSeparator({ alwaysRender = false, className, ...props }: CommandSeparatorProps) { const { store } = useCommandContext('CommandSeparator'); const searching = useStore(store, () => store.search !== ''); if (searching && !alwaysRender) return null; return ( <div aria-hidden="true" data-slot="command-separator" {...props} className={cn('sprout-command-separator', className)} /> ); } function textOf(node: ReactNode): string { if (typeof node === 'string' || typeof node === 'number') return String(node); if (Array.isArray(node)) return node.map(textOf).join(''); if (isValidElement<{ children?: ReactNode }>(node)) return textOf(node.props.children); return ''; } export interface CommandItemProps extends Omit<ComponentProps<'div'>, 'value' | 'onSelect'> { value?: string; keywords?: readonly string[]; disabled?: boolean; onSelect?: (value: string) => void; forceMount?: boolean; 'data-checked'?: boolean; } export function CommandItem({ value, keywords, disabled = false, onSelect, forceMount = false, className, children, style, onClick, onPointerMove, onPointerDown, ...props }: CommandItemProps) { const { store } = useCommandContext('CommandItem'); const group = useContext(GroupContext); const id = useId(); const resolved = (value ?? textOf(children)).trim(); const select = useRef(() => {}); select.current = () => { if (!disabled) onSelect?.(resolved); }; const keywordKey = (keywords ?? []).join('\u0000'); useLayoutEffect(() => { store.items.set(id, { value: resolved, keywords: keywordKey ? keywordKey.split('\u0000') : [], group, select: () => select.current(), }); store.schedule(); return () => { store.items.delete(id); if (store.active === id) store.needsFirst = true; store.schedule(); }; }, [store, id, resolved, keywordKey, group]); const visible = useStore(store, () => forceMount || store.isVisible(id)); const active = useStore(store, () => store.active === id); const order = useStore(store, () => store.order(store.scores.get(id))); if (!visible) return null; return ( <div id={id} role="option" aria-selected={active} aria-disabled={disabled || undefined} data-selected={active || undefined} data-disabled={disabled || undefined} data-value={resolved} data-slot="command-item" {...props} style={{ order, ...style }} className={cn('sprout-command-item', className)} onPointerDown={event => { onPointerDown?.(event); if (!event.defaultPrevented) event.preventDefault(); }} onPointerMove={event => { onPointerMove?.(event); if (!disabled && !event.defaultPrevented) store.setActive(id); }} onClick={event => { onClick?.(event); if (!event.defaultPrevented) select.current(); }} > {children} <CheckIcon size="md" aria-hidden="true" className="sprout-command-item-check" /> </div> ); } export type CommandShortcutProps = ComponentProps<'span'>; export function CommandShortcut({ className, ...props }: CommandShortcutProps) { return <span data-slot="command-shortcut" {...props} className={cn('sprout-command-shortcut', className)} />; } export interface CommandDialogProps extends Omit<DialogProps, 'children'> { title?: string; description?: string; className?: string; showCloseButton?: boolean; closeLabel?: string; container?: DialogContentProps['container']; children: ReactNode; } export function CommandDialog({ title = 'Command Palette', description = 'Search for a command to run...', className, showCloseButton = false, closeLabel, container, children, ...props }: CommandDialogProps) { return ( <Dialog {...props}> <DialogContent placement="top" showCloseButton={showCloseButton} closeLabel={closeLabel} container={container} className={cn('sprout-command-dialog', className)} > <DialogTitle className="sprout-command-sr-only">{title}</DialogTitle> <DialogDescription className="sprout-command-sr-only">{description}</DialogDescription> {children} </DialogContent> </Dialog> ); }And the files it imports:
lib/sprout/icons/check-icon.tsxlib/sprout/icons/create-icon.tsxlib/sprout/icons/search-icon.tsx
Add the styles to your global CSS, after
@import "tailwindcss".@layer components { .sprout-command { box-sizing: border-box; border-radius: var(--sprout-radius-panel); background: var(--sprout-surface); width: 100%; min-width: 0; height: 100%; color: var(--sprout-text); font-family: var(--sprout-font); font-size: var(--sprout-text-sm); outline: none; flex-direction: column; padding: 4px; line-height: 1.25rem; display: flex; overflow: hidden; } .sprout-command :where(p) { margin: 0; } .sprout-command-sr-only { clip-path: inset(50%); white-space: nowrap; border: 0; width: 1px; height: 1px; margin: -1px; padding: 0; position: absolute; overflow: hidden; } .sprout-command-input-wrapper { padding: 4px 4px 0; } .sprout-command-input-group { box-sizing: border-box; height: var(--sprout-control-height); border: 1px solid color-mix(in oklab, var(--sprout-input) 30%, transparent); border-radius: calc(var(--sprout-radius-panel) - 4px); background: color-mix(in oklab, var(--sprout-input) 30%, transparent); cursor: text; align-items: center; gap: 6px; min-width: 0; padding-inline: 8px; display: flex; } .sprout-command-input-group:has(.sprout-command-input:focus-visible) { border-color: var(--sprout-border); } .sprout-command-input-group:has(.sprout-command-input:disabled) { opacity: .5; cursor: not-allowed; } .sprout-command-input-icon { width: 16px; height: 16px; color: var(--sprout-muted); pointer-events: none; flex-shrink: 0; } .sprout-command-input { min-width: 0; height: 100%; color: var(--sprout-text); font: inherit; background: none; border: 0; outline: none; flex: 1; margin: 0; padding: 0; } .sprout-command-input::placeholder { color: var(--sprout-muted); opacity: 1; } .sprout-command-input:disabled { cursor: not-allowed; } .sprout-command-list { overscroll-behavior: contain; scrollbar-width: none; outline: none; max-height: 18rem; scroll-padding-block: 4px; overflow: hidden auto; } .sprout-command-list::-webkit-scrollbar { display: none; } .sprout-command-list-sizer, .sprout-command-group-items { flex-direction: column; min-width: 0; display: flex; } .sprout-command-empty { color: var(--sprout-muted); text-align: center; overflow-wrap: anywhere; padding: 24px 8px; } .sprout-command-group { min-width: 0; color: var(--sprout-text); padding: 4px; overflow: hidden; } .sprout-command-group[hidden] { display: none; } .sprout-command-group-heading { color: var(--sprout-muted); font-size: var(--sprout-text-xs); overflow-wrap: anywhere; padding: 6px 8px; font-weight: 500; line-height: 1rem; } .sprout-command-separator { background: var(--sprout-line); flex-shrink: 0; height: 1px; margin-inline: -4px; } .sprout-command-item { box-sizing: border-box; min-width: 0; min-height: var(--sprout-control-height); border-radius: calc(var(--sprout-radius-control) - 2px); color: var(--sprout-text); overflow-wrap: anywhere; cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent; outline: none; align-items: center; gap: 8px; padding: 6px 8px; display: flex; position: relative; } [data-slot="dialog-content"] .sprout-command-item { border-radius: calc(var(--sprout-radius-panel) - 4px); } .sprout-command-item > :where(svg), .sprout-command-item > :where(span) > :where(svg:only-child) { pointer-events: none; flex-shrink: 0; width: 16px; height: 16px; } .sprout-command-item[data-selected] { background: var(--sprout-hover); color: var(--sprout-text); } .sprout-command-item[data-disabled] { opacity: .5; cursor: default; pointer-events: none; } .sprout-command-item-check { color: var(--sprout-text); opacity: 0; margin-inline-start: auto; } .sprout-command-item[data-checked="true"] > .sprout-command-item-check { opacity: 1; } .sprout-command-item:has( > .sprout-command-shortcut) > .sprout-command-item-check { display: none; } .sprout-command-shortcut { color: var(--sprout-muted); font-size: var(--sprout-text-xs); letter-spacing: .1em; white-space: nowrap; flex-shrink: 0; margin-inline-start: auto; padding-inline-start: 12px; } .sprout-command-item[data-selected] .sprout-command-shortcut { color: var(--sprout-text); } .sprout-dialog-content.sprout-command-dialog { --sprout-dialog-padding: 0px; border-radius: calc(var(--sprout-radius-panel) + 4px); gap: 0; padding: 0; overflow: hidden; } .sprout-command-dialog > .sprout-command { border-radius: inherit; } .sprout-command-dialog .sprout-command-list { max-height: min(20rem, 76dvh - 3rem); } @media (pointer: coarse) { .sprout-command-item { min-height: 2.75rem; } } @media (forced-colors: active) { .sprout-command-item[data-selected] { outline-offset: -1px; outline: 2px solid highlight; } .sprout-command-input-group { border-color: canvastext; } } @media (prefers-reduced-motion: no-preference) { .sprout-command-item { transition: background-color var(--sprout-motion-fast) var(--sprout-motion-ease); } .sprout-command-item-check { transition: opacity var(--sprout-motion-fast) var(--sprout-motion-ease); } .sprout-command-input-group { transition: border-color var(--sprout-motion-fast) var(--sprout-motion-ease); } } }Import it from
@/components/ui/command. Update the paths if your@/alias points elsewhere.
pnpm add @tulipfarm/sprout@import "tailwindcss";
@import "@tulipfarm/sprout/styles.css";The package keeps the source and ships fixes with each release. Import from @tulipfarm/sprout/command.
Command playground
Filter and select commands inline. Type to filter; arrow keys, Home, End, and Enter work from the search field.
Chosen: Nothing selected
Usage
import {
Command,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
CommandSeparator,
CommandShortcut,
} from "@tulipfarm/sprout/command";
<Command>
<CommandInput aria-label="Search sample commands" placeholder="Search sample commands…" />
<CommandList>
<CommandEmpty>No matching commands.</CommandEmpty>
<CommandGroup heading="Suggestions">
<CommandItem onSelect={newDraft}>
<Plus size={16} aria-hidden="true" />
New draft
<CommandShortcut>⌘ N</CommandShortcut>
</CommandItem>
<CommandItem onSelect={openFolder}>
<Folder size={16} aria-hidden="true" />
Open folder
</CommandItem>
</CommandGroup>
<CommandSeparator />
<CommandGroup heading="Settings">
<CommandItem disabled>Unavailable action</CommandItem>
</CommandGroup>
</CommandList>
</Command>Give the input an aria-label or pass label to Command. Each item matches on its text unless you pass a value, and onSelect receives that value. Groups and separators hide while nothing in them matches.
Command palette
CommandDialog pins a Command near the top of the screen in a 24rem dialog. Its title and description are visually hidden but announced. Escape closes it; add showCloseButton for a corner close button. Wire your own shortcut such as ⌘K to open it.
Command palette
CommandDialog pins a Command near the top of the screen. Its title and description are visually hidden; Escape closes it.
Last command: Nothing run yet
Pickers in a popover
Put a Command in PopoverContent size="menu" or size="picker"; both have no padding, so the search and list run edge to edge. Set data-checked on the current item to show a trailing check. Use a long value such as label plus description so both are searchable. Content after Command, such as an effort setting, stays outside the list.
Composer pickers
A Command inside a menu-size (24rem) and a picker-size (18rem) popover above the chat composer. The trailing check marks the current choice.
Ask about your workspace…
Controlled search and list states
Pass value and onValueChange to CommandInput to clear the search when the popover closes or from a button in CommandEmpty. When an item's value is an id, pass its name in keywords so it still matches. Show loading, error with retry, and empty-workspace notes as siblings after CommandList.
Project scope
A picker-size Command with a controlled search, an unlabeled first group, ids as values with names as keywords, and a recovery action when nothing matches.
No action yet
API
Command is a div that owns the search and the active item. It takes label, loop (wrap at the ends), shouldFilter (set false to filter items yourself), and filter(value, search, keywords), which returns a score where 0 hides the item. Matches are ranked: prefix, then word start, then substring, then letters in order. The default is exported as defaultCommandFilter.
CommandInput takes input props plus controlled value and onValueChange, and forwards ref. CommandList scrolls at 18rem. CommandEmpty renders only when nothing matches.CommandGroup takes an optional heading and forceMount. CommandSeparator hides while searching unless alwaysRender.
CommandItem takes value, keywords, disabled, onSelect, forceMount, and data-checked. CommandShortcut is a trailing hint and replaces the check. CommandDialog takes the Dialog root props plus title, description, showCloseButton, closeLabel, container, and className. Every part sets a data-slot.
Accessibility
The input is a combobox that controls the listbox. Focus stays in the input and the active option is announced through aria-activedescendant. Arrow keys move, Home and End jump to the ends, ⌘ or Ctrl with arrows jumps to the first or last item, Alt with arrows jumps between groups, Ctrl+N and Ctrl+P also move, and Enter chooses. Disabled items are skipped. Buttons inside the Command, such as Clear search, keep their own keys.
When nothing matches, the list drops its listbox role, the input reports aria-expanded="false", and the empty message and its actions read as ordinary content. Separators are decorative and hidden from assistive technology.
Highlight and check changes fade over 120ms and stop when reduced motion is requested. In forced-colors mode the active item gets an outline.
Theme tokens
Command uses --sprout-surface, --sprout-text, --sprout-muted, --sprout-line, --sprout-input, --sprout-hover, --sprout-focus, and the control and panel radii. It needs no brand color, so it looks the same with the neutral and TulipFarm themes in light and dark mode.