Skip to content

Commit

Permalink
Merge pull request #2086 from JedWatson/fix/numeric-multi-select
Browse files Browse the repository at this point in the history
Fix/numeric multi select
  • Loading branch information
gwyneplaine authored Oct 25, 2017
2 parents 381ebc1 + bdcb33f commit ca09183
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,9 @@ class Select extends React.Component {
/** support optionally passing in the `nextProps` so `componentWillReceiveProps` updates will function as expected */
const props = typeof nextProps === 'object' ? nextProps : this.props;
if (props.multi) {
if (typeof value === 'string') value = value.split(props.delimiter);
if (typeof value === 'string') {
value = value.split(props.delimiter);
}
if (!Array.isArray(value)) {
if (value === null || value === undefined) return [];
value = [value];
Expand All @@ -503,7 +505,7 @@ class Select extends React.Component {
let { options, valueKey } = props;
if (!options) return;
for (var i = 0; i < options.length; i++) {
if (options[i][valueKey] === value) return options[i];
if (String(options[i][valueKey]) === String(value)) return options[i];
}
}

Expand Down
21 changes: 16 additions & 5 deletions test/Select-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -719,8 +719,8 @@ describe('Select', () => {

expect(instance, 'to contain',
<span className="Select-multi-value-wrapper">
<div><span className="Select-value-label">Two</span></div>
<div><span className="Select-value-label">One</span></div>
<div><span className="Select-value-label">Two</span></div>
<div><span className="Select-value-label">One</span></div>
</span>);
});

Expand All @@ -739,8 +739,19 @@ describe('Select', () => {

expect(instance, 'to contain',
<span className="Select-multi-value-wrapper">
<div><span className="Select-value-label">Three</span></div>
<div><span className="Select-value-label">Four</span></div>
<div><span className="Select-value-label">Three</span></div>
<div><span className="Select-value-label">Four</span></div>
</span>);
});
it('supports updating the values as a string', () => {
wrapper.setPropsForChild({
value: '3,4',
});

expect(instance, 'to contain',
<span className="Select-multi-value-wrapper">
<div><span className="Select-value-label">Three</span></div>
<div><span className="Select-value-label">Four</span></div>
</span>);
});

Expand All @@ -765,7 +776,7 @@ describe('Select', () => {

expect(instance, 'to contain',
<span className="Select-multi-value-wrapper">
<div><span className="Select-value-label">Zero</span></div>
<div><span className="Select-value-label">Zero</span></div>
</span>);
});

Expand Down

0 comments on commit ca09183

Please sign in to comment.