@@ -115,7 +115,8 @@ module.exports = React.createClass({
115
115
props . onClick = this . selectOption . bind ( this , child ) ;
116
116
props . onFocus = this . handleOptionFocus ;
117
117
props . onKeyDown = this . handleOptionKeyDown . bind ( this , child ) ;
118
- props . onMouseEnter = this . handleOptionMouseEnter . bind ( this , index ) ;
118
+ props . onMouseEnter = this . handleOptionMouseEnter . bind (
119
+ this , optionIndexes . length - 1 ) ;
119
120
} . bind ( this ) ) ;
120
121
return {
121
122
optionIndexes : optionIndexes ,
@@ -311,20 +312,23 @@ module.exports = React.createClass({
311
312
312
313
focusPrevious : function ( ) {
313
314
if ( this . state . menu . isEmpty ) return ;
314
- var last = this . props . children . length - 1 ;
315
+ var last = this . state . menu . optionIndexes . length - 1 ;
315
316
var index = this . state . focusedIndex == null ?
316
317
last : this . state . focusedIndex - 1 ;
317
318
this . focusOptionAtIndex ( index ) ;
318
319
} ,
319
320
320
321
focusSelectedOption : function ( ) {
322
+ // we have to do two hops to go from the DOM index to option index
321
323
var selectedDomIndex ;
324
+
325
+ // hop 1: dom index
322
326
React . Children . forEach ( this . props . children , function ( child , index ) {
323
327
if ( child . props . value === this . state . value )
324
328
selectedDomIndex = index ;
325
329
} . bind ( this ) ) ;
326
330
327
- // find the option index
331
+ // hop 2: option index
328
332
var selectedOptionIndex ;
329
333
this . state . menu . optionIndexes . forEach ( function ( domIndex , optIndex ) {
330
334
if ( domIndex === selectedDomIndex ) selectedOptionIndex = optIndex ;
@@ -347,6 +351,8 @@ module.exports = React.createClass({
347
351
return inputValue || value ;
348
352
} ,
349
353
354
+ // index is the index of the option among the list of only options,
355
+ // NOT among all elements in the DOM
350
356
focusOptionAtIndex : function ( index ) {
351
357
if ( ! this . state . isOpen && this . state . value )
352
358
return this . focusSelectedOption ( ) ;
0 commit comments