@@ -9,7 +9,6 @@ var fuzzy = require('fuzzy');
99var classNames = require ( 'classnames' ) ;
1010
1111var IDENTITY_FN = function ( input ) { return input ; } ;
12- var SHOULD_SEARCH_VALUE = function ( input ) { return input && input . trim ( ) . length > 0 ; } ;
1312var _generateAccessor = function ( field ) {
1413 return function ( object ) { return object [ field ] ; } ;
1514} ;
@@ -54,7 +53,8 @@ var Typeahead = React.createClass({
5453 customListComponent : React . PropTypes . oneOfType ( [
5554 React . PropTypes . element ,
5655 React . PropTypes . func
57- ] )
56+ ] ) ,
57+ showOptionsWhenEmpty : React . PropTypes . bool
5858 } ,
5959
6060 getDefaultProps : function ( ) {
@@ -75,7 +75,8 @@ var Typeahead = React.createClass({
7575 onBlur : function ( event ) { } ,
7676 filterOption : null ,
7777 defaultClassNames : true ,
78- customListComponent : TypeaheadSelector
78+ customListComponent : TypeaheadSelector ,
79+ showOptionsWhenEmpty : false
7980 } ;
8081 } ,
8182
@@ -95,8 +96,14 @@ var Typeahead = React.createClass({
9596 } ;
9697 } ,
9798
99+ _shouldSkipSearch : function ( input ) {
100+ var emptyValue = ! input || input . trim ( ) . length == 0 ;
101+ return ! this . props . showOptionsWhenEmpty && emptyValue ;
102+ } ,
103+
98104 getOptionsForValue : function ( value , options ) {
99- if ( ! SHOULD_SEARCH_VALUE ( value ) ) { return [ ] ; }
105+ if ( this . _shouldSkipSearch ( value ) ) { return [ ] ; }
106+
100107 var filterOptions = this . _generateFilterFunction ( ) ;
101108 var result = filterOptions ( value , options ) ;
102109 if ( this . props . maxVisible ) {
@@ -132,7 +139,7 @@ var Typeahead = React.createClass({
132139
133140 _renderIncrementalSearchResults : function ( ) {
134141 // Nothing has been entered into the textbox
135- if ( ! this . state . entryValue ) {
142+ if ( this . _shouldSkipSearch ( this . state . entryValue ) ) {
136143 return "" ;
137144 }
138145
0 commit comments