Description
Is your feature request related to a problem? Please describe.
I often find myself in a situation where I need to sort the options based on the user's search query. Currently, I resort to implementing a fake-asynchronous search to achieve the desired sorting of results, but it would be more efficient and cleaner to have a native feature for sorting based on the search query.
Describe the solution you'd like
I would like to propose the addition of a new property, sortBy
, that can be utilized alongside filterBy
. This property should allow users to specify a custom sorting function that will be applied to the filtered options based on the user's search query. For example:
<Typeahead
// existing props...
filterBy={(option, props) => {/* existing filter logic */}}
sortBy={(options, props) => {
// Custom sorting logic based on the search query
// ...
return sortedOptions;
}}
/>
How is this solution useful to others?
This feature would be beneficial for scenarios where users expect a customized sorting order based on their search input. It provides a more flexible and generalized way to handle result sorting, addressing a common use case across various applications.
Describe alternatives you've considered
As mentioned earlier, the current workaround involves implementing a simulated asynchronous search to manually sort the results in the onSearch
handler. However, having a built-in option for dynamic sorting based on the search query would streamline the process and make the code more maintainable.