diff --git a/src/typeahead/index.js b/src/typeahead/index.js index eda1cfd9..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 }; }, @@ -118,7 +121,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) { @@ -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 ) {