@@ -124,7 +124,7 @@ var Typeahead = React.createClass({
124124 _hasCustomValue : function ( ) {
125125 if ( this . props . allowCustomValues > 0 &&
126126 this . state . entryValue . length >= this . props . allowCustomValues &&
127- this . state . visible . indexOf ( this . state . entryValue ) < 0 ) {
127+ this . state . visible . indexOf ( this . state . entryValue ) === - 1 ) {
128128 return true ;
129129 }
130130 return false ;
@@ -183,17 +183,25 @@ var Typeahead = React.createClass({
183183 var formInputOptionString = formInputOption ( option ) ;
184184
185185 nEntry . value = optionString ;
186- this . setState ( { visible : this . getOptionsForValue ( optionString , this . props . options ) ,
187- selection : formInputOptionString ,
188- entryValue : optionString } ) ;
186+ this . setState (
187+ {
188+ visible : this . getOptionsForValue ( optionString , this . props . options ) ,
189+ selection : formInputOptionString ,
190+ entryValue : optionString
191+ }
192+ ) ;
189193 return this . props . onOptionSelected ( option , event ) ;
190194 } ,
191195
192196 _onTextEntryUpdated : function ( ) {
193197 var value = this . refs . entry . value ;
194- this . setState ( { visible : this . getOptionsForValue ( value , this . props . options ) ,
195- selection : null ,
196- entryValue : value } ) ;
198+ this . setState (
199+ {
200+ visible : this . getOptionsForValue ( value , this . props . options ) ,
201+ selection : null ,
202+ entryValue : value
203+ }
204+ ) ;
197205 } ,
198206
199207 _onEnter : function ( event ) {
@@ -205,17 +213,19 @@ var Typeahead = React.createClass({
205213 } ,
206214
207215 _onEscape : function ( ) {
208- this . setState ( {
209- selectionIndex : null
210- } ) ;
216+ this . setState (
217+ {
218+ selectionIndex : null
219+ }
220+ ) ;
211221 } ,
212222
213223 _onTab : function ( event ) {
214224 var selection = this . getSelection ( ) ;
215225 var option = selection ?
216226 selection : ( this . state . visible . length > 0 ? this . state . visible [ 0 ] : null ) ;
217227
218- if ( option === null && this . _hasCustomValue ( ) ) {
228+ if ( option === null ) {
219229 option = this . _getCustomValue ( ) ;
220230 }
221231
@@ -252,7 +262,11 @@ var Typeahead = React.createClass({
252262 newIndex -= length ;
253263 }
254264
255- this . setState ( { selectionIndex : newIndex } ) ;
265+ this . setState (
266+ {
267+ selectionIndex : newIndex
268+ }
269+ ) ;
256270 } ,
257271
258272 navDown : function ( ) {
@@ -292,7 +306,8 @@ var Typeahead = React.createClass({
292306
293307 componentWillReceiveProps : function ( nextProps ) {
294308 this . setState ( {
295- visible : this . getOptionsForValue ( nextProps . entryValue , nextProps . options )
309+ visible : this . getOptionsForValue ( nextProps . value , nextProps . options ) ,
310+ entryValue : nextProps . value
296311 } ) ;
297312 } ,
298313
@@ -316,13 +331,13 @@ var Typeahead = React.createClass({
316331 { ...this . props . inputProps }
317332 placeholder = { this . props . placeholder }
318333 className = { inputClassList }
319- value = { this . state . entryValue }
320334 defaultValue = { this . props . defaultValue }
321335 onChange = { this . _onChange }
322336 onKeyDown = { this . _onKeyDown }
323337 onKeyUp = { this . props . onKeyUp }
324338 onFocus = { this . props . onFocus }
325339 onBlur = { this . props . onBlur }
340+ value = { this . props . value }
326341 />
327342 { this . _renderIncrementalSearchResults ( ) }
328343 </ div >
0 commit comments