Description
Provide a general summary of the feature here
It would be nice if the filtering here could be override directly on the ListBox
declaratively. Like
// No filtering at all
<ListBox filter={null} />
// Custom filter
<ListBox filter={(item, input) => customFilter(item, input)} />
Right now, to achieve custom filtering, you need to setup the combox as a controlled component: https://react-spectrum.adobe.com/react-aria/useComboBox.html#custom-filtering
And then repeat the items you want in the context on both the Listbox and Combox. This introduces local state where you don't need to have it.
I'd be happy to make the PR if the team is okay with it
Alternatively, I can also see a solution where the filter
is overridable on Combobox itself.
<Combobox filter={(item, input) => customFilter(item, input)} />
Another solution that I would enjoy seeing, would be enabling this pattern:
// Inside Combobox > Listbox > ListboxSection >
<Collection
items={item.options.filter((o) =>
contains(o.value, use(ComboBoxStateContext)?.inputValue ?? '') ||
contains(o.label, use(ComboBoxStateContext)?.inputValue ?? ''),
)}
This work require being able to simply toggle the filtering on/off.
🤔 Expected Behavior?
Custom filtering on Comboboxes should not require local state
😯 Current Behavior
Custom filtering on Comboboxes requires local state
💁 Possible Solution
All a filter
prop on Listbox
OR on components that provide the filter currently (e.g. Combobox
)
🔦 Context
I had to introduce local state because I wanted the filtering to react to the aria-label and some invisible metadata. I felt as though I was breaking a pattern by introducing local state.
💻 Examples
No response
🧢 Your Company/Team
No response
🕷 Tracking Issue
No response