Skip to content

Commit

Permalink
Fix backspace handling for non-multi select controls. Fixes JedWatson…
Browse files Browse the repository at this point in the history
  • Loading branch information
MrLeebo authored and agirton committed Jun 14, 2017
1 parent 07dc061 commit 40a9eb2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ const Select = createClass({
var valueArray = this.getValueArray(this.props.value);
if (!valueArray.length) return;
if (valueArray[valueArray.length-1].clearableValue === false) return;
this.setValue(valueArray.slice(0, valueArray.length - 1));
this.setValue(this.props.multi ? valueArray.slice(0, valueArray.length - 1) : null);
},

removeValue (value) {
Expand Down
13 changes: 13 additions & 0 deletions test/Select-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1850,6 +1850,19 @@ describe('Select', () => {
]);
});

it('removes the last item with backspace', () => {

wrapper.setPropsForChild({
multi: false,
value: 'one'
});
onChange.reset(); // Ignore previous onChange calls

pressBackspace();

expect(onChange, 'was called with', null);
});

it('doesn\'t show the X if clearableValue=false', () => {

setValueProp(['two']);
Expand Down

0 comments on commit 40a9eb2

Please sign in to comment.