From 28244c7868fe732a4d4130809b322f61e30f5086 Mon Sep 17 00:00:00 2001 From: David Uebelacker Date: Thu, 16 Mar 2017 09:30:19 +0100 Subject: [PATCH] special handing for backspace if inputValue contains one character --- src/Select.js | 2 ++ test/Select-test.js | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/src/Select.js b/src/Select.js index fc09e715f0..d106f09643 100644 --- a/src/Select.js +++ b/src/Select.js @@ -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 diff --git a/test/Select-test.js b/test/Select-test.js index d8df285436..a1829e9e5d 100644 --- a/test/Select-test.js +++ b/test/Select-test.js @@ -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