Feature Request: Allow for sorting options in filterOptions prop
See original GitHub issueIn v1
overriding the standard filterOptions
meant that you could return the options
in a completely different order based on the search, whereas the new filterOption
is only giving us the option to specify if that option should be shown or not.
I think that having some way of ordering the results is useful in lots of cases. Here’s one with some dummy data. Let’s suppose that my options is a long list of names and we expect that someone will probably start typing the person’s first name in order to get to that person as quickly as possible, but they might also only know a surname.
If we have the following names at the start of the options, "Alexa Nabil"
, "Alexandra Bilani"
, "Bill Ward"
and the user starts typing "Bi"
then currently the default behaviour of react-select is to show the options in their original, alphabetical order, but I’d suggest that "Bill Ward"
, "Alexandra Bilani"
, "Alexa Nabil"
makes more sense once there’s the user input. That’s possible with filterOptions
because you can sort the options at the same time as filtering them, but v2 leaves me without a way of doing this.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:25
- Comments:9
Top GitHub Comments
It sounds like we need a companion function for
filterOption
–sortOptions
, with the shape of:Meanwhile i had to do something like this:
Hope it helps someone