Skip to content

Commit

Permalink
Fix selected option focus when valueKey is not "value"
Browse files Browse the repository at this point in the history
  • Loading branch information
Betree committed May 18, 2017
1 parent 196c7bb commit 45f5665
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -1108,15 +1108,15 @@ var Select = (0, _createReactClass2['default'])({
});
},

getFocusableOptionIndex: function getFocusableOptionIndex(selectedOption) {
getFocusableOptionIndex: function getFocusableOptionIndex(selectedOption, valueKey) {
var options = this._visibleOptions;
if (!options.length) return null;

var focusedOption = this.state.focusedOption || selectedOption;
if (focusedOption && !focusedOption.disabled) {
var focusedOptionIndex = -1;
options.some(function (option, index) {
var isOptionEqual = option.value === focusedOption.value;
var isOptionEqual = option[valueKey] === focusedOption[valueKey];
if (isOptionEqual) {
focusedOptionIndex = index;
}
Expand Down Expand Up @@ -1166,7 +1166,7 @@ var Select = (0, _createReactClass2['default'])({
var options = this._visibleOptions = this.filterOptions(this.props.multi ? this.getValueArray(this.props.value) : null);
var isOpen = this.state.isOpen;
if (this.props.multi && !options.length && valueArray.length && !this.state.inputValue) isOpen = false;
var focusedOptionIndex = this.getFocusableOptionIndex(valueArray[0]);
var focusedOptionIndex = this.getFocusableOptionIndex(valueArray[0], this.props.valueKey);

var focusedOption = null;
if (focusedOptionIndex !== null) {
Expand Down Expand Up @@ -1235,4 +1235,4 @@ var Select = (0, _createReactClass2['default'])({
});

exports['default'] = Select;
module.exports = exports['default'];
module.exports = exports['default'];

0 comments on commit 45f5665

Please sign in to comment.