tbleckert / react-select-search

⚡️ Lightweight select component for React
https://react-select-search.com
MIT License
676 stars 149 forks source link

Define Custom Search #119

Closed Shadrack1701 closed 3 years ago

Shadrack1701 commented 3 years ago

How can you define a custom search function with react-select-search? I see mention of the filterOptions callback but I have no idea where/how this actually gets uses. Any help here would be appreciated. Fuse isn't performing well enough.

tbleckert commented 3 years ago

Hi! You can check the Async example for how to hook into search changes and return your own set of options. The filterOptions attribute mentioned in the readme is a leftover from a previous version, sorry about that. Maybe a custom filter function is more what you need though if you just want to replace fuse with your own search. I'll look into that.

Also, if fuse isn't working as you want it to, you could try to modify the fuse options, specifically: location, threshold, distance and keys.

Shadrack1701 commented 3 years ago

Yeah, specifically a custom filter function is what I was looking for. I'll look into your Async example as a stop gap. Thanks for getting back to me!

Shadrack1701 commented 3 years ago

I'm going to stick with fuse even though there is a pretty bad lag from typing and the search results. Also when switching to async you can no longer click to make your selection; that same issue exists in the demo. Default values also don't seem to work correctly with the async getOptions either. Creating my own search function I could boost performance and debounce it to reduce the lag. This is still better than react-select for me as this is truly lightweight and not full of tons of dependencies blocked by our strict CSP settings.

tbleckert commented 3 years ago

Hm interesting, I'll take a look at the click bug. Regarding the lag, do you have a lot of options? Over at least 300 options could create some lag because the options are not virtualized (yet). But should be possible to boost the performance a bit when typing even without virtualization. I'll look into to it.

FYI, I've initiated a small rewrite that will make Fuse pluggable instead of built-in, that will open up the possibility to add your own fuzzy search/filter function.

Shadrack1701 commented 3 years ago

Yeah i have around 2k options, and the click bug I mention looks like is already reported: 107