react-widgets icon indicating copy to clipboard operation
react-widgets copied to clipboard

Combobox: Filter resets on blur → reopening ignores previous input

Open patorelovsky opened this issue 7 months ago • 1 comments

When a user types something that doesn’t match existing options, the combobox shows "No results". If they close it via the toggle (arrow), then reopen, the filtered state remains correctly. However, if they click outside (triggering onBlur) and then reopen, the filtering is lost and all options are shown again. This is because shouldFilter.current is reset on blur, and useFilteredData ignores previous searchTerm.

Steps to reproduce:

  1. Type a non-matching string, e.g. asdf.
  2. Observe "No results".
  3. Click outside to blur.
  4. Click the toggle arrow to reopen.
  5. The full options list appears, even though the input still contains asdf.

Expected behavior: After blur, reopening should preserve the filtered state (still show no results) if the input remains unchanged.

Possible fixes:

  • Option A: Don’t reset shouldFilter.current = false on blur in ComboboxImpl, so the previous filter remains active.
  • Option B: Expose a searchTerm prop (controlled) and allow consumers to maintain filter state across blur/open cycles.
  • Option C: Document the current behavior as intentional (but this seems unlikely).

Context from source: useFilteredData(...) uses searchTerm, but since shouldFilter.current is set to false in Combobox's internal didHandle(focused), the Combobox passes '' as searchTerm after blur — so reopening resets the filter.

Version: latest (react-widgets v5.8.6)

patorelovsky avatar Jun 30 '25 08:06 patorelovsky