From f3b181d566aad7b7db01b7f9aff6f98fc2989306 Mon Sep 17 00:00:00 2001 From: Derek Hamilton Date: Wed, 13 Dec 2017 11:45:06 -0500 Subject: [PATCH 1/4] Account for onSelectResetsInput when props change --- package.json | 4 ++-- src/Select.js | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index c60425ed99..5495d7a5cc 100644 --- a/package.json +++ b/package.json @@ -83,9 +83,9 @@ "cover": "cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text mocha", "coveralls": "cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text mocha && cat coverage/lcov.info | coveralls", "lint": "eslint .", - "deploy": "NODE_ENV=production nps publish", + "deploy": "cross-env NODE_ENV=production nps publish", "start": "webpack-dev-server --progress", - "test": "NODE_ENV=test mocha --compilers js:babel-core/register", + "test": "cross-env NODE_ENV=test mocha --compilers js:babel-core/register", "precommit": "lint-staged && yarn run test" }, "files": [ diff --git a/src/Select.js b/src/Select.js index c89587baa6..0e955cd7ea 100644 --- a/src/Select.js +++ b/src/Select.js @@ -102,7 +102,7 @@ class Select extends React.Component { this.setState({ required: false }); } - if (this.state.inputValue && this.props.value !== nextProps.value) { + if (this.state.inputValue && this.props.value !== nextProps.value && this.props.onSelectResetsInput) { this.setState({ inputValue: this.handleInputValueChange('') }); } } @@ -565,6 +565,7 @@ class Select extends React.Component { this.hasScrolledToOption = false; } const updatedValue = this.props.onSelectResetsInput ? '' : this.state.inputValue; + console.log(this.props.onSelectResetsInput, this.state.inputValue, updatedValue); if (this.props.multi) { this.setState({ focusedIndex: null, From 2c2630ef87ae03c8f77bd3b88b948cb1ddadc1ad Mon Sep 17 00:00:00 2001 From: Derek Hamilton Date: Wed, 13 Dec 2017 12:31:45 -0500 Subject: [PATCH 2/4] onSelectResetsInput tests --- src/Select.js | 1 - test/Select-test.js | 60 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/src/Select.js b/src/Select.js index 0e955cd7ea..46f8977e07 100644 --- a/src/Select.js +++ b/src/Select.js @@ -565,7 +565,6 @@ class Select extends React.Component { this.hasScrolledToOption = false; } const updatedValue = this.props.onSelectResetsInput ? '' : this.state.inputValue; - console.log(this.props.onSelectResetsInput, this.state.inputValue, updatedValue); if (this.props.multi) { this.setState({ focusedIndex: null, diff --git a/test/Select-test.js b/test/Select-test.js index d0cb508e07..2fc273ce40 100644 --- a/test/Select-test.js +++ b/test/Select-test.js @@ -2129,6 +2129,66 @@ describe('Select', () => { }); + describe('with multi=true and onSelectResetsInput=false', () => { + it('should have retained inputValue after accepting selection', () => { + options = [ + { value: 'one', label: 'One' }, + { value: 'two', label: 'Two' }, + { value: 'three', label: 'Three' }, + { value: 'four', label: 'Four' } + ]; + + // Render an instance of the component + wrapper = createControlWithWrapper({ + value: '', + options: options, + multi: true, + closeOnSelect: false, + removeSelected: false, + onSelectResetsInput: false + }); + + instance.setState({ + isFocused: true + }); + + clickArrowToOpen(); + typeSearchText('two'); + pressEnterToAccept(); + setValueProp('two'); // trigger componentWillReceiveProps + + expect(instance.state.inputValue, 'to equal', 'two'); + }); + + it('should have reset the inputValue after accepting selection', () => { + options = [ + { value: 'one', label: 'One' }, + { value: 'two', label: 'Two' }, + { value: 'three', label: 'Three' }, + { value: 'four', label: 'Four' } + ]; + + // Render an instance of the component + wrapper = createControlWithWrapper({ + value: '', + options: options, + multi: true, + closeOnSelect: false, + removeSelected: false + }); + + instance.setState({ + isFocused: true + }); + + clickArrowToOpen(); + typeSearchText('two'); + pressEnterToAccept(); + + expect(instance.state.inputValue, 'to equal', ''); + }); + }); + describe('with removeSelected=false', () => { beforeEach(() => { options = [ From 22e46fa731fc0dc38ec71cceb06f183b4c637e38 Mon Sep 17 00:00:00 2001 From: Jed Watson Date: Thu, 14 Dec 2017 23:26:09 +1100 Subject: [PATCH 3/4] Update test descriptions As suggested by @yuri-sakharov --- test/Select-test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Select-test.js b/test/Select-test.js index 2fc273ce40..390944ef67 100644 --- a/test/Select-test.js +++ b/test/Select-test.js @@ -2129,8 +2129,8 @@ describe('Select', () => { }); - describe('with multi=true and onSelectResetsInput=false', () => { - it('should have retained inputValue after accepting selection', () => { + describe('with multi=true different onSelectResetsInput', () => { + it('should have retained inputValue after accepting selection with onSelectResetsInput=false', () => { options = [ { value: 'one', label: 'One' }, { value: 'two', label: 'Two' }, From 552a7cdfb81959ffb29af0eaad84e951d8c6975e Mon Sep 17 00:00:00 2001 From: Jed Watson Date: Thu, 14 Dec 2017 23:27:51 +1100 Subject: [PATCH 4/4] Updating test description As suggested by @yuri-sakharov --- test/Select-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Select-test.js b/test/Select-test.js index 390944ef67..f0ca6d119f 100644 --- a/test/Select-test.js +++ b/test/Select-test.js @@ -2160,7 +2160,7 @@ describe('Select', () => { expect(instance.state.inputValue, 'to equal', 'two'); }); - it('should have reset the inputValue after accepting selection', () => { + it('should have reset the inputValue after accepting selection when onSelectResetsInput= true or not set', () => { options = [ { value: 'one', label: 'One' }, { value: 'two', label: 'Two' },