Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/typeahead/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
},

Expand All @@ -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) {
Expand Down Expand Up @@ -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);
},

Expand Down Expand Up @@ -336,13 +340,13 @@ var Typeahead = React.createClass({
onFocus={this._onFocus}
onBlur={this._onBlur}
/>
{ this._renderIncrementalSearchResults() }
{ this.state.showResults && this._renderIncrementalSearchResults() }
</div>
);
},

_onFocus: function(event) {
this.setState({isFocused: true}, function () {
this.setState({isFocused: true, showResults: true}, function () {
this._onTextEntryUpdated();
}.bind(this));
if ( this.props.onFocus ) {
Expand Down