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..46f8977e07 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('') }); } } diff --git a/test/Select-test.js b/test/Select-test.js index d0cb508e07..f0ca6d119f 100644 --- a/test/Select-test.js +++ b/test/Select-test.js @@ -2129,6 +2129,66 @@ describe('Select', () => { }); + 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' }, + { 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 when onSelectResetsInput= true or not set', () => { + 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 = [