Skip to content

Commit 40a9eb2

Browse files
MrLeeboagirton
authored andcommitted
Fix backspace handling for non-multi select controls. Fixes JedWatson#638 (JedWatson#773)
1 parent 07dc061 commit 40a9eb2

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/Select.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ const Select = createClass({
644644
var valueArray = this.getValueArray(this.props.value);
645645
if (!valueArray.length) return;
646646
if (valueArray[valueArray.length-1].clearableValue === false) return;
647-
this.setValue(valueArray.slice(0, valueArray.length - 1));
647+
this.setValue(this.props.multi ? valueArray.slice(0, valueArray.length - 1) : null);
648648
},
649649

650650
removeValue (value) {

test/Select-test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,6 +1850,19 @@ describe('Select', () => {
18501850
]);
18511851
});
18521852

1853+
it('removes the last item with backspace', () => {
1854+
1855+
wrapper.setPropsForChild({
1856+
multi: false,
1857+
value: 'one'
1858+
});
1859+
onChange.reset(); // Ignore previous onChange calls
1860+
1861+
pressBackspace();
1862+
1863+
expect(onChange, 'was called with', null);
1864+
});
1865+
18531866
it('doesn\'t show the X if clearableValue=false', () => {
18541867

18551868
setValueProp(['two']);

0 commit comments

Comments
 (0)