Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/numeric multi select #2086

Merged
merged 5 commits into from
Oct 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,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 @@ -489,7 +491,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 Expand Up @@ -781,7 +783,7 @@ class Select extends React.Component {
[this._instancePrefix + '-list']: isOpen,
});
return (

<div
{...divProps}
role="combobox"
Expand Down
21 changes: 16 additions & 5 deletions test/Select-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -718,8 +718,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 @@ -738,8 +738,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 @@ -764,7 +775,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