react-typeahead
react-typeahead copied to clipboard
Click outside must close suggestions.
Click outside must close suggestions.
How to?
After any page updates suggestions are opens again (((
Why not focused element show suggestions? Please add rules to showResults:
- entryValue in_array searchResults and searchResults.length == 1 > hide
- isFocused == false > hide
On my project I use this concept:
- create
isSuggestionOpen
state, and set it tofalse
by default - while user focus on input, set that state to
true
(viaonFocus
props) - if user click outside input, set that state to
false
(viaonBlur
props) - in
customClasses.results
props, I add this class (just for example):Typeahead__container Typeahead__container--${this.state.isSuggestionOpen ? 'isOpen' : 'isHide'}
and control it viavisibility
,opacity
, ordisplay
. It's your option. - it works for me. May help you :)
simiply, we can set showResults to false on _onBlur Function
this.setState({isFocused: false, showResults: false}, function () {
instead of just,
this.setState({isFocused: false }, function () {
it works with me :smile: