Skip to content

Search filtering breaks when using backspace - options list not refreshing properly #70

@pkuliga

Description

@pkuliga

Bug Description

When using the search functionality in the MultiSelect component, typing characters works correctly and filters the options as expected. However, when using the backspace key to remove characters from the search query, the options list does not refresh properly and may show incorrect or stale filtering results.

Steps to Reproduce

  1. Open a MultiSelect component with searchable enabled (searchable={true})
  2. Click to open the dropdown
  3. Type some characters in the search input to filter options (this works correctly)
  4. Use backspace to remove characters from the search query
  5. Observe that the options list does not update/refresh to show the correct filtered results

Expected Behavior

When removing characters with backspace, the options list should refresh and show all options that match the updated (shorter) search query, just like when typing characters.

Actual Behavior

The options list remains filtered based on the previous search state and doesn't update when characters are removed via backspace.

Root Cause

The issue is caused by conflicting filtering mechanisms:

  1. The cmdk library's built-in filtering (enabled by default in the Command component)
  2. The MultiSelect component's custom filtering logic in the filteredOptions useMemo

When backspace is used, these two filtering systems get out of sync, causing the options list to not refresh properly.

Proposed Solution

Add shouldFilter={false} to the Command component to disable the cmdk library's built-in filtering and rely solely on the custom filtering logic:

<Command shouldFilter={false}>
  {/* rest of the component */}
</Command>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions