From 53760e18f54c4b092c17a335a5ee922021814dfc Mon Sep 17 00:00:00 2001 From: Mike James Date: Wed, 1 Jun 2016 14:36:23 +0100 Subject: [PATCH 1/2] removed strange global variable. --- src/typeahead/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/typeahead/index.js b/src/typeahead/index.js index eda1cfd9..1ffdd63d 100644 --- a/src/typeahead/index.js +++ b/src/typeahead/index.js @@ -118,7 +118,7 @@ var Typeahead = React.createClass({ if (this._shouldSkipSearch(value)) { return []; } var searchOptions = this._generateSearchFunction(); - return result = searchOptions(value, options); + return searchOptions(value, options); }, setEntryText: function(value) { From 6cc4422ba44a2b2cf8892496b06d5d868917ccdd Mon Sep 17 00:00:00 2001 From: Mike James Date: Wed, 1 Jun 2016 14:45:46 +0100 Subject: [PATCH 2/2] only show results when focused --- src/typeahead/index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/typeahead/index.js b/src/typeahead/index.js index 1ffdd63d..5a2b72bc 100644 --- a/src/typeahead/index.js +++ b/src/typeahead/index.js @@ -102,6 +102,9 @@ var Typeahead = React.createClass({ // Keep track of the focus state of the input element, to determine // whether to show options when empty (if showOptionsWhenEmpty is true) isFocused: false, + + // true when focused, false onOptionSelected + showResults: false }; }, @@ -197,7 +200,8 @@ var Typeahead = React.createClass({ nEntry.value = optionString; this.setState({searchResults: this.getOptionsForValue(optionString, this.props.options), selection: formInputOptionString, - entryValue: optionString}); + entryValue: optionString, + showResults: false}); return this.props.onOptionSelected(option, event); }, @@ -336,13 +340,13 @@ var Typeahead = React.createClass({ onFocus={this._onFocus} onBlur={this._onBlur} /> - { this._renderIncrementalSearchResults() } + { this.state.showResults && this._renderIncrementalSearchResults() } ); }, _onFocus: function(event) { - this.setState({isFocused: true}, function () { + this.setState({isFocused: true, showResults: true}, function () { this._onTextEntryUpdated(); }.bind(this)); if ( this.props.onFocus ) {