From 1b06702ef4a15be0ab495995f8ca4a020bbb845f Mon Sep 17 00:00:00 2001 From: Edmond Pruteanu Date: Sun, 12 Mar 2017 02:56:17 +0200 Subject: [PATCH 1/3] Fixed Numeric Values Multi-Select MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Selected options weren’t being added to the input in Multi-Select mode for Numeric Values --- src/Select.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Select.js b/src/Select.js index fc09e715f0..fdc7935f5f 100644 --- a/src/Select.js +++ b/src/Select.js @@ -568,7 +568,13 @@ const Select = React.createClass({ /** 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); + // convert string array to numbers array if made of numbers only + if (!value.some(isNaN)) { + value = value.map(Number); + } + } if (!Array.isArray(value)) { if (value === null || value === undefined) return []; value = [value]; From a0965e0665cce750cb027e8fa1e60a0444a25e09 Mon Sep 17 00:00:00 2001 From: Charles Lee Date: Mon, 23 Oct 2017 16:43:05 +1100 Subject: [PATCH 2/3] add string coercion to expandValues() --- src/Select.js | 8 ++------ test/Select-test.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Select.js b/src/Select.js index e2b4743bf3..a79a004439 100644 --- a/src/Select.js +++ b/src/Select.js @@ -469,10 +469,6 @@ class Select extends React.Component { if (props.multi) { if (typeof value === 'string') { value = value.split(props.delimiter); - // convert string array to numbers array if made of numbers only - if (!value.some(isNaN)) { - value = value.map(Number); - } } if (!Array.isArray(value)) { if (value === null || value === undefined) return []; @@ -495,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]; } } @@ -787,7 +783,7 @@ class Select extends React.Component { [this._instancePrefix + '-list']: isOpen, }); return ( - +
{
Four
); }); + it('supports updating the values as a string', () => { + wrapper.setPropsForChild({ + value: '3,4', + }); + + expect(instance, 'to contain', + +
Three
+
Four
+
); + }); it('supports updating the value to a single value', () => { From bdcb33f2e4bb4c640a486dfcfb9baff9d952968a Mon Sep 17 00:00:00 2001 From: Charles Lee Date: Mon, 23 Oct 2017 17:31:00 +1100 Subject: [PATCH 3/3] spacing fixes --- test/Select-test.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/Select-test.js b/test/Select-test.js index 7b1fdef21a..23f6933f45 100644 --- a/test/Select-test.js +++ b/test/Select-test.js @@ -718,8 +718,8 @@ describe('Select', () => { expect(instance, 'to contain', -
Two
-
One
+
Two
+
One
); }); @@ -738,8 +738,8 @@ describe('Select', () => { expect(instance, 'to contain', -
Three
-
Four
+
Three
+
Four
); }); it('supports updating the values as a string', () => { @@ -749,8 +749,8 @@ describe('Select', () => { expect(instance, 'to contain', -
Three
-
Four
+
Three
+
Four
); }); @@ -775,7 +775,7 @@ describe('Select', () => { expect(instance, 'to contain', -
Zero
+
Zero
); });