Skip to main content
By default, cmdk uses its built-in command-score algorithm — a fuzzy matching library — to rank items against the current search query. Items with a score above 0 are shown; items are sorted by descending score. Groups are re-ordered by the highest score of any item they contain. Filtering and sorting run synchronously on every keystroke, so the list updates with no visible delay.

Default behavior

No configuration needed. Items are filtered and sorted automatically:
Item values are always trimmed with .trim() before scoring. If you provide a value prop explicitly, it is trimmed too.

Custom filter function

Pass a filter prop to Command to replace the default algorithm. The function receives (value, search, keywords?) and must return a number between 0 and 1:
  • 1 — exact match, shown at the top
  • 0 — no match, hidden
  • Values in between affect sort order

Keywords

Add a keywords prop to Command.Item to provide aliases that also match during search. Keywords are trimmed and passed to your filter function as the third argument:
To use keywords in a custom filter function:
Keywords are trimmed with .trim() before being passed to the filter function.

Disabling automatic filtering

Set shouldFilter={false} to disable all built-in filtering and sorting. You are then responsible for rendering only the items that should be visible based on the current query:
shouldFilter={false} is recommended when you need to bring your own virtualization or when you are filtering a very large list on the server.

Using the default filter directly

cmdk exports defaultFilter, the same function used internally. Import it if you want to extend the default behavior rather than replace it entirely: