Skip to content

Commit

Permalink
fix(Select): should not del disabled item with backspace. fix #1196
Browse files Browse the repository at this point in the history
  • Loading branch information
bindoon committed Oct 8, 2019
1 parent a5f5519 commit 81b0e75
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/select/select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,14 @@ class Select extends Base {
case KEYCODE.BACKSPACE:
if ((mode === 'multiple' && showSearch) || mode === 'tag') {
// 在多选并且有搜索的情况下,删除最后一个 tag
this.handleDeleteTag(e);
const valueDS = this.valueDataSource.valueDS;
if (
valueDS &&
valueDS.length &&
!valueDS[valueDS.length - 1].disabled
) {
this.handleDeleteTag(e);
}
} else if (
mode === 'single' &&
hasClear &&
Expand Down
19 changes: 19 additions & 0 deletions test/select/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,25 @@ describe('Select', () => {
wrapper.find('div.next-tag .next-tag-close-btn').simulate('click');
});

it('should not delete disabled item with BACKSPACE', done => {
wrapper.setProps({
mode: 'tag',
dataSource: [{value: '10001', label: 'Lucy King'}, {value: '10003', label: 'Tom Cat', disabled: true}],
value: ['10001', '10003'],
onChange: function(value) {
assert(value.length === 1);
done();
},
});

wrapper.find('input').simulate('keydown', {
key: 'backSpace',
keyCode: 8,
});

wrapper.find('div.next-tag .next-tag-close-btn').first().simulate('click');
});

it('should support mode=tag with visible=false', done => {
wrapper.setProps({
mode: 'tag',
Expand Down

0 comments on commit 81b0e75

Please sign in to comment.