yury-dymov / react-autocomplete-input

Autocomplete input field for React
https://yury-dymov.github.io/react-autocomplete-input/
MIT License
199 stars 65 forks source link

text is showing @undefined #15

Closed kafeltz closed 6 years ago

kafeltz commented 6 years ago

Steps to reproduce the bug:

1- access the demo page https://yury-dymov.github.io/react-autocomplete-input/

2- type @ap and press ARROW DOWN, the apricot will be selected (highlighted)

3- press ple (completing apple word), it will show only apple in the list, but not selected

4- press enter (without selecting apple) It will show @undefined

I know the problem. this.state.selection is 1 when there is 0 in options.

I'm seding PR to fix that. Take a look.

yury-dymov commented 6 years ago

That's amazing, thank you, will review asap.

I will also add a test case if it is missing, so don't worry much about it.

kafeltz commented 6 years ago

https://github.com/yury-dymov/react-autocomplete-input/pull/16

kafeltz commented 6 years ago

I wonder about this kind of fix, I thought the selector id should have come right from the function parameter. Anyway, the issue is const slug is undefined because the index is 1 and options is 0.

yury-dymov commented 6 years ago

I eventually came up with choosing the first element in the drop-down if we are out of range. Not the 100% best approach but it was an edge case in the first place