tbleckert / react-select-search

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

Select item on Enter #258

Closed romikforest closed 9 months ago

romikforest commented 1 year ago

Is it possible to make this component allow me to select the item just pressing Enter when I already have fully typed it in the search area? Doesn't work in my case for some reason and I have to click the item in the dropdown list with a mouse.

flapstones commented 1 year ago

I have this same issue, if you search and then move down the items using the arrow keys and then pressing enter to select doesn't work

section14 commented 1 year ago

+1 On this issue. It seems like it uses the index from the original options array, instead of the filtered version. Let's say this is the original options array:

[
    {name: 'Apple', value: 1, index: 0},
    {name: 'Boy', value: 2, index: 1},
    {name: 'Cat', value: 3, index: 2},
    {name: 'Dog', value: 4, index: 3},
    {name: 'Airplane', value: 5, index: 4},
]

Then type A to filter the options down to:

[
    {name: 'Apple', value: 1, index: 0},
    {name: 'Airplane', value: 5, index: 1},
]

When you press enter to make a selection, you end up getting:

 {name: 'Boy', value: 2, index: 1},

from the original options, instead of the filtered options array

jwmann commented 10 months ago

+1 On this issue. It seems like it uses the index from the original options array, instead of the filtered version. Let's say this is the original options array:

[
    {name: 'Apple', value: 1, index: 0},
    {name: 'Boy', value: 2, index: 1},
    {name: 'Cat', value: 3, index: 2},
    {name: 'Dog', value: 4, index: 3},
    {name: 'Airplane', value: 5, index: 4},
]

Then type A to filter the options down to:

[
    {name: 'Apple', value: 1, index: 0},
    {name: 'Airplane', value: 5, index: 1},
]

When you press enter to make a selection, you end up getting:

 {name: 'Boy', value: 2, index: 1},

from the original options, instead of the filtered options array

I also have this exact issue, was also mentioned in #264

tbleckert commented 9 months ago

Fixed in v4.17 by https://github.com/tbleckert/react-select-search/pull/265