Skip to content

Commit 4ef4274

Browse files
committed
Merge pull request #203 from pebblecode/feature/hide-show-results
Feature/hide show results
2 parents 61fa555 + 6cc4422 commit 4ef4274

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/typeahead/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ var Typeahead = React.createClass({
102102
// Keep track of the focus state of the input element, to determine
103103
// whether to show options when empty (if showOptionsWhenEmpty is true)
104104
isFocused: false,
105+
106+
// true when focused, false onOptionSelected
107+
showResults: false
105108
};
106109
},
107110

@@ -197,7 +200,8 @@ var Typeahead = React.createClass({
197200
nEntry.value = optionString;
198201
this.setState({searchResults: this.getOptionsForValue(optionString, this.props.options),
199202
selection: formInputOptionString,
200-
entryValue: optionString});
203+
entryValue: optionString,
204+
showResults: false});
201205
return this.props.onOptionSelected(option, event);
202206
},
203207

@@ -336,13 +340,13 @@ var Typeahead = React.createClass({
336340
onFocus={this._onFocus}
337341
onBlur={this._onBlur}
338342
/>
339-
{ this._renderIncrementalSearchResults() }
343+
{ this.state.showResults && this._renderIncrementalSearchResults() }
340344
</div>
341345
);
342346
},
343347

344348
_onFocus: function(event) {
345-
this.setState({isFocused: true}, function () {
349+
this.setState({isFocused: true, showResults: true}, function () {
346350
this._onTextEntryUpdated();
347351
}.bind(this));
348352
if ( this.props.onFocus ) {

0 commit comments

Comments
 (0)