fmoo / react-typeahead

Pure react-based typeahead and typeahead-tokenizer
ISC License
677 stars 232 forks source link

onOptionSelected does not trigger on click #205

Open amitava82 opened 8 years ago

amitava82 commented 8 years ago

2.0.0-alpha.5 Only keyboard event works

zdhickman commented 8 years ago

FYI https://github.com/HubSpot/react-typeahead/pull/6 has a quick workaround that uses onMouseDown instead of onClick to check for clicks on options. If this is still appropriate behavior for the typeahead, I can patch to this repo

em0ney commented 7 years ago

I had this issue, but in my case, I was trying to hide results onBlur. The blur was firing before the selection was made. Just putting that here incase it helps you or anyone else

jennykortina commented 7 years ago

@zdhickman is there anyway to get an onlick or onmousedown event right now? I tried both and neither work? I'm using css to expand/contract the search box on focus, which isn't allowing me to use onclick to send the typeahead slection

mateuspontes commented 7 years ago

I had this issue, I fixed with a setTimeout while they patch a better solution.

onBlur(e) {
    e.stopPropagation();
    e.preventDefault();
    setTimeout(() => {
        if (this.refs.typeahead.state['showResults']) this.refs.typeahead.setState({showResults: false})
    }, 150);
}