tbleckert / react-select-search

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

Should the first search result be pre-selected to enable one-click keyboard selection? #124

Open aaroncawte opened 3 years ago

aaroncawte commented 3 years ago

In the Single select - Search example, if you type a substring of your desired option and press Enter, it closes the selector with no change in selection (still nothing or the previous selection).

It would be really cool if pressing Enter would automatically highlight and select the top result, while at the moment you must press Down to highlight it then press Enter to submit.

tbleckert commented 3 years ago

@aaroncawte Ah, hm. Sounds like a good idea. Thanks for the feedback!

cbaucom commented 2 years ago

@tbleckert - I'm trying to achieve something similar where I just want to start typing and press Enter without having to navigate down into the dropdown list (My first option in my dropdown is "show all results" for whatever you are searching).

If this issue is still open, do you know another way to handle this?

and-poulsen commented 1 year ago

I've made a little hack that, when you search, triggers a simulated keydown event if the "highlighted" prop is not set

<SelectSearch
    renderValue={(valueProps, snapshot, className) => (
        <input {...valueProps} onKeyPress={(e) => {
            if(snapshot.highlighted < 0) {
                valueProps.onKeyDown( { key: "down", preventDefault: () => {1} } )
            } 
        } />
    )}}
/>

cc: @cbaucom