Command
A command palette provides a searchable list of actions or items. Users type into a search input to filter and select commands via keyboard or mouse. This pattern is commonly used for quick-access command palettes (e.g., Ctrl+K interfaces), searchable menus, and action launchers.
The component renders a search region containing a text input and a listbox for results. The search value is bindable, allowing consumers to implement their own filtering logic and dynamically update the listbox content.
Implementation Notes
- Wraps content in a
<div>withrole="search"andaria-labelfor semantic search region - Contains an
<input type="search">withautocomplete="off"to prevent browser autocomplete interference - Contains a
<div>withrole="listbox"for displaying filtered results - Supports two-way binding on the
valueprop component - Children slot is rendered inside the listbox for consumer-controlled list items
- Spreads
restPropson the outer search container
Props
label: string (required) -- accessible name for both the search region and the inputplaceholder: string (default:undefined) -- placeholder text for the search inputvalue: string (default:"", bindable) -- current search text, supports two-way binding via two-wayvaluebindingchildren: slot (required) -- listbox content, typically option or command items...restProps: any additional HTML attributes spread onto the outer<div>
Usage
Application command palette triggered by Ctrl+K:
<Command label="Command palette" placeholder="Type a command..." value={query}>
<div role="option" tabindex="-1" onclick={() => navigate('/dashboard')}>Go to Dashboard</div>
<div role="option" tabindex="-1" onclick={() => navigate('/settings')}>Open Settings</div>
<div role="option" tabindex="-1" onclick={() => toggleTheme()}>Toggle Dark Mode</div>
</Command>
Admin panel action launcher with dynamic filtering:
<Command label="Actions" placeholder="Search actions..." value={actionQuery}>
{#each filteredActions as action}
<div role="option" tabindex="-1" onclick={() => action.execute()}>
{action.name} <kbd>{action.shortcut}</kbd>
</div>
{/each}
</Command>
Keyboard Interactions
- Tab: Moves focus into and out of the search input
- Additional keyboard navigation (arrow keys within the listbox) should be implemented by the consumer
ARIA
role="search"-- identifies the outer container as a search landmark regionaria-label={label}-- provides accessible name for the search region and inputrole="listbox"-- identifies the results container as a listbox for selectable optionsaria-label={label}-- provides accessible name for the listbox
When to Use
- Use Command for quick-access search interfaces such as Ctrl+K action launchers or searchable menus.
- Use Command when users need to search and execute actions from a large set without navigating through menus.
- Use Command for keyboard-driven navigation where users can jump to pages, run actions, or switch contexts.
- Use Command in developer tools, admin panels, or productivity applications where power users expect a command palette.
When Not to Use
- Do not use Command for site search or content search -- use SearchInput instead.
- Do not use Command for form input with a dropdown list of options -- use Combobox instead.
- Do not use Command for navigation menus that should always be visible -- use NavigationMenu instead.
Headless
This headless Command component provides a <div> with role="search" and aria-label, an <input type="search"> with autocomplete="off", and a <div> with role="listbox" for displaying results. The consumer provides all visual styling including modal/overlay presentation, result item layout, keyboard shortcut hints, grouping headers, and animations.
Styles
The consumer provides all CSS styling. The component renders with a .command class for targeting. No default styles are included — this is a fully headless component.
Testing
- Verify the component renders a
<div>element with classcommand - Verify role="search"` -- identifies the outer container as a search landmark region
- Verify aria-label={label}` -- provides accessible name for the search region and input
- Verify role="listbox"` -- identifies the results container as a listbox for selectable options
- Verify aria-label={label}` -- provides accessible name for the listbox
- Verify keyboard interactions work correctly
- Verify pass-through attributes are applied
Advice
- Designers: Present the command palette in a modal overlay centered on screen. Group related commands and show keyboard shortcut hints alongside each action.
- Developers: Implement filtering logic by reacting to the bindable
valueprop. Add arrow key navigation for the listbox items in your consumer code. Pair with a Dialog for modal presentation.
Related components
combobox— a text input combined with a dropdown list for filtering optionsmenu— a list of actions or options triggered by a buttonsearch-input— an input for entering a search query <input type="search">
References
- WAI-ARIA Listbox Pattern: https://www.w3.org/WAI/ARIA/apg/patterns/listbox/
- WAI-ARIA Combobox Pattern: https://www.w3.org/WAI/ARIA/apg/patterns/combobox/