ezequiel/react-typeahead-component

Hook for option selected via Enter

ntharim opened this issue · 4 comments

There's onOptionClick for when an option is clicked but how do you detect option selection when the user presses Enter after moving up and down with arrow keys?

Good question. This is a good use case I may have missed. For our use cases, we set the input value when arrowing, and the input value was enough information to perform some action. I can see use cases where the input value isn't necessarily enough, and the actual selected option data is needed.

I can pass the option data, and selectedIndex as two extra parameters when onKeyDown is fired (like onOptionClick). What do you think?

Yeah that would work. Another option is to have onOptionSelected that can detect both clicks and Enter keydowns. Either is fine for me so up to you what you want to implement :D.

@nthtran I've added this new functionality as part of release 0.3.0. I decided to go with the onKeyDown approach, as it will probably offer greater flexibility when strange requirements come into play.

Absolutely. Keep up the good work! 👍