downshift icon indicating copy to clipboard operation
downshift copied to clipboard

Allow searching for strings with spaces and for substrings

Open rollie42 opened this issue 4 years ago • 5 comments

This is a question/request, but I am happy to try to contribute if you can point me in the right direction :)

I notice when using useSelect, if I have a number of entries in the Select dropdown like "San Francisco", "San Diego", and "San Antonio", If I type "San F", it doesn't select the appropriate entry because the space key causes the dropdown to close. So - is there a way to prevent this to allow for searching names with spaces? Is this desired by default, or is there some reason it can't be an option (if it isn't the default behavior)? My thinking is to treat the space character as it currently is treated, unless it comes within 1s after a different keystroke that yielded a matching entry in the select control.

Similar question: if I know all my cities start with 'San', I might just search with 'franci', and expect it to select "San Francisco" as it's the only one containing that substring. Is this behavior somehow already supported? Can/should it be?

Again I haven't contributed to downshift before, but I'm happy to give it a crack, if you can point me toward where I can find the relevant logic!

rollie42 avatar Nov 21 '21 06:11 rollie42

Hi! This is a great catch!

I think that we should check, on spacebar, if we have any input value, and if we do, we should add the space to the input value, instead of performing the selection.

This should be fixable in the useSelect reducer. It should also contain unit tests, and I think it could be pretty straightforward to code.

Want to give it a try?

silviuaavram avatar Dec 24 '21 10:12 silviuaavram

Sure, I'll give it a go :)

rollie42 avatar Dec 25 '21 02:12 rollie42

Is this still open? I'd like to work on it if so

lenniezelk avatar Apr 12 '22 09:04 lenniezelk

I didn't find time for this after all, so as far as I know it's available

On Tue, Apr 12, 2022, 6:27 PM Leonard Kioi kinyanjui < @.***> wrote:

Is this still open? I'd like to work on it if so

— Reply to this email directly, view it on GitHub https://github.com/downshift-js/downshift/issues/1339#issuecomment-1096436362, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAPHN3OFP7CC4IZB6BW6V4LVEU6WNANCNFSM5IOZFYKA . You are receiving this because you authored the thread.Message ID: @.***>

rollie42 avatar Apr 12 '22 13:04 rollie42

@silviuaavram how do i manually test my changes in the browser while developing locally?

lenniezelk avatar Apr 15 '22 08:04 lenniezelk

there is npm run docs:dev to start docusaurus with the local code.

silviuaavram avatar Dec 16 '22 16:12 silviuaavram