@@ -26,6 +26,7 @@ var Typeahead = createReactClass({
2626 placeholder : PropTypes . string ,
2727 disabled : PropTypes . bool ,
2828 textarea : PropTypes . bool ,
29+ clearOnSelect : PropTypes . bool ,
2930 inputProps : PropTypes . object ,
3031 onOptionSelected : PropTypes . func ,
3132 onChange : PropTypes . func ,
@@ -69,6 +70,7 @@ var Typeahead = createReactClass({
6970 placeholder : "" ,
7071 disabled : false ,
7172 textarea : false ,
73+ clearOnSelect : false ,
7274 inputProps : { } ,
7375 onOptionSelected : function ( option ) { } ,
7476 onChange : function ( event ) { } ,
@@ -199,11 +201,14 @@ var Typeahead = createReactClass({
199201 var formInputOption = Accessor . generateOptionToStringFor ( this . props . formInputOption || displayOption ) ;
200202 var formInputOptionString = formInputOption ( option ) ;
201203
202- nEntry . value = optionString ;
203- this . setState ( { searchResults : this . getOptionsForValue ( optionString , this . props . options ) ,
204- selection : formInputOptionString ,
205- entryValue : optionString ,
206- showResults : false } ) ;
204+ var valueAfterSelect = this . props . clearOnSelect ? '' : optionString ;
205+ var selectionAfterSelect = this . props . clearOnSelect ? '' : formInputOptionString ;
206+
207+ nEntry . value = valueAfterSelect ;
208+ this . setState ( { searchResults : this . getOptionsForValue ( valueAfterSelect , this . props . options ) ,
209+ selection : selectionAfterSelect ,
210+ entryValue : valueAfterSelect ,
211+ showResults : ! ! this . props . clearOnSelect } ) ;
207212 return this . props . onOptionSelected ( option , event ) ;
208213 } ,
209214
@@ -310,7 +315,7 @@ var Typeahead = createReactClass({
310315
311316 componentWillReceiveProps : function ( nextProps ) {
312317 var searchResults = this . getOptionsForValue ( this . state . entryValue , nextProps . options ) ;
313- var showResults = Boolean ( searchResults . length ) && this . state . isFocused ;
318+ var showResults = ! ! this . props . clearOnSelect || ( Boolean ( searchResults . length ) && this . state . isFocused ) ;
314319 this . setState ( {
315320 searchResults : searchResults ,
316321 showResults : showResults
0 commit comments