Fuzzy-search using useFilter? #2785
-
I am building a timezone selector using I am wondering if I can use fuzzy-search as my timezone field looks like If I type I want it to use Fuzzy Search. Is this possible? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
You can do whatever filtering you want. We have a useFilter hook that provides some basic things out of the box. https://react-spectrum.adobe.com/react-aria/useComboBox.html#custom-filtering but it's just returning true or false to the javascript filter function. If you make your own filtering, you probably want to make use of our useCollator hook so it's easier to internationalize. You can see the implementation of our useFilter here https://github.com/adobe/react-spectrum/blob/main/packages/@react-aria/i18n/src/useFilter.ts#L29 it's not too complex. |
Beta Was this translation helpful? Give feedback.
-
I used the custom filtering section by only replacing it with fuse.js (demo → https://codesandbox.io/s/combobox-with-fuse-js-t7u4c?file=/src/App.tsx) const fuse = React.useMemo(() => new Fuse(timezonesList, options), []);
const filteredItems = React.useMemo(
() => fuse.search(filterValue).map((tz) => tz.item),
[filterValue, fuse]
); Eventually, replaced |
Beta Was this translation helpful? Give feedback.
I used the custom filtering section by only replacing it with fuse.js (demo → https://codesandbox.io/s/combobox-with-fuse-js-t7u4c?file=/src/App.tsx)
Eventually, replaced
fuse.js
with https://github.com/ajitid/fzf-for-js as fuse was giving a bug but fzf worked fine! Only need to replace the above section a bit :)