Skip to content

Commit

Permalink
Merge 22e46fa into 700b79a
Browse files Browse the repository at this point in the history
  • Loading branch information
dehamilton committed Dec 14, 2017
2 parents 700b79a + 22e46fa commit 839be7e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
2 changes: 1 addition & 1 deletion src/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('') });
}
}
Expand Down
60 changes: 60 additions & 0 deletions test/Select-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
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 = [
Expand Down

0 comments on commit 839be7e

Please sign in to comment.