Skip to content

Commit

Permalink
.is-selected class bugfix for 'value' objects that don't have exactly…
Browse files Browse the repository at this point in the history
… the same structure/order as 'options'
  • Loading branch information
Danny Herran committed Apr 18, 2016
1 parent bbe4032 commit 655b9ee
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,29 @@ function stringifyValue (value) {
}
}

if (!Array.prototype.findIndex) {
Array.prototype.findIndex = function(predicate) {
if (this === null) {
throw new TypeError('Array.prototype.findIndex called on null or undefined');
}
if (typeof predicate !== 'function') {
throw new TypeError('predicate must be a function');
}
var list = Object(this);
var length = list.length >>> 0;
var thisArg = arguments[1];
var value;

for (var i = 0; i < length; i++) {
value = list[i];
if (predicate.call(thisArg, value, i, list)) {
return i;
}
}
return -1;
};
}

const stringOrNode = React.PropTypes.oneOfType([
React.PropTypes.string,
React.PropTypes.node
Expand Down Expand Up @@ -737,7 +760,7 @@ const Select = React.createClass({
let renderLabel = this.props.optionRenderer || this.getOptionLabel;

return options.map((option, i) => {
let isSelected = valueArray && valueArray.indexOf(option) > -1;
let isSelected = valueArray && valueArray.findIndex(x => x[this.props.valueKey] == option[this.props.valueKey]) > -1;
let isFocused = option === focusedOption;
let optionRef = isFocused ? 'focused' : null;
let optionClass = classNames(this.props.optionClassName, {
Expand Down

0 comments on commit 655b9ee

Please sign in to comment.