Skip to content

Commit

Permalink
special handing for backspace if inputValue contains one character
Browse files Browse the repository at this point in the history
  • Loading branch information
uebelack committed Mar 16, 2017
1 parent 2249f26 commit 28244c7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,8 @@ const Select = React.createClass({
if (!this.state.inputValue && this.props.backspaceRemoves) {
event.preventDefault();
this.popValue();
} else if (this.props.backspaceRemoves && this.state.inputValue.length === 1) {
this.popValue();
}
return;
case 9: // tab
Expand Down
8 changes: 8 additions & 0 deletions test/Select-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1782,6 +1782,14 @@ describe('Select', () => {
expect(onChange, 'was called with', [{ label: 'Four', value: 'four' }]);
});

it('removes the last selected option with backspace when search text is set', () => {
typeSearchText('a');
setValueProp(['four','three']);
onChange.reset(); // Ignore previous onChange calls
pressBackspace();
expect(onChange, 'was called with', [{ label: 'Four', value: 'four' }]);
});

it('does not remove the last selected option with backspace when backspaceRemoves=false', () => {

// Disable backspace
Expand Down

0 comments on commit 28244c7

Please sign in to comment.