Command
Fast, composable command menu for keyboard-first navigation and actions
Preview
Installation
Usage
Examples
Command Dialog
Display command menu in a modal dialog with keyboard shortcut support.
Press ⌘+k to open
With Footer
Add footer content with keyboard navigation hints.
Press ⌘+k to open
Fuzzy Search
Enable fuzzy matching for more flexible searching across multiple fields.
Press ⌘+j to open
Virtualized
Use virtualization for large lists (100+ items) to maintain smooth performance. Only renders items visible in the viewport, dramatically reducing DOM nodes.
Key concepts:
- Use
useListVirtualizerhook - Handles scroll positioning, keyboard navigation, and item measurement. See useListVirtualizer docs for full API reference. - External filtering - Compute
filteredItemsyourself and passfilter={null}to Command. The hook needs both arrays to calculate proper aria attributes. - Replace
CommandListwithCommandVirtualizedList- AcceptsscrollRefandtotalSizefrom the hook. - Spread
rootProps- Contains virtualization state for Base UI integration.
Filtering options:
- Default filtering: Use
useCommandFilterfor the samecontains/startsWith/endsWithmatchers as Command's built-in filter - Fuzzy search: Use useFuzzyFilter for relevance-sorted results across multiple fields
- Server-side filtering: Pass the same array to both
itemsandfilteredItems - Custom filtering: Use any filtering method (native
.filter(), third-party libraries, etc.)
API Reference
The Command component is built on top of Base UI's Autocomplete and Dialog. All Base UI props are supported. The documentation below only covers custom props and modified defaults specific to our implementation.
For the complete Base UI API, see the Base UI Autocomplete documentation.
Props
Command
Root component that manages command menu state and keyboard navigation. Wraps Base UI's Autocomplete.Root.
CommandList
Scrollable container for command items with empty state handling. Wraps Base UI's Autocomplete.List.
CommandVirtualizedList
Virtualized scrollable container for large lists. Use with useListVirtualizer hook for optimal performance with 100+ items.
Utilities
highlightText
Highlights matching portions of text by wrapping them in <mark> tags. Useful for showing which parts of a command match the user's input.
See highlightText for full documentation and API reference.
Hooks
useCommandFilter
Exposes Base UI's built-in filter matchers for external filtering. Required when using virtualization since you must compute filteredItems yourself.
Returns
| Property | Type | Description |
|---|---|---|
contains | (item, query, getItemLabel) => boolean | Returns true if item label contains query (case-insensitive) |
startsWith | (item, query, getItemLabel) => boolean | Returns true if item label starts with query |
endsWith | (item, query, getItemLabel) => boolean | Returns true if item label ends with query |
useFuzzyFilter
Provides fuzzy matching capabilities for flexible searching across multiple fields. Returns filter functions compatible with Base UI's Autocomplete.
See useFuzzyFilter for full documentation and API reference.
useListVirtualizer
Provides virtualization for large command lists using TanStack Virtual. Abstracts scroll handling, item positioning, and keyboard navigation.
See useListVirtualizer for full documentation and API reference.