From 45f5665e495a4d305743aef22bcc045bc374e1e1 Mon Sep 17 00:00:00 2001 From: Benjamin Piouffle Date: Thu, 18 May 2017 20:46:43 +1100 Subject: [PATCH] Fix selected option focus when valueKey is not "value" --- lib/Select.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Select.js b/lib/Select.js index ea34e932ea..8b0c1d052d 100644 --- a/lib/Select.js +++ b/lib/Select.js @@ -1108,7 +1108,7 @@ var Select = (0, _createReactClass2['default'])({ }); }, - getFocusableOptionIndex: function getFocusableOptionIndex(selectedOption) { + getFocusableOptionIndex: function getFocusableOptionIndex(selectedOption, valueKey) { var options = this._visibleOptions; if (!options.length) return null; @@ -1116,7 +1116,7 @@ var Select = (0, _createReactClass2['default'])({ 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; } @@ -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) { @@ -1235,4 +1235,4 @@ var Select = (0, _createReactClass2['default'])({ }); exports['default'] = Select; -module.exports = exports['default']; \ No newline at end of file +module.exports = exports['default'];