From 81b0e756da70de31129c9e9493f7a5f8c7372c8a Mon Sep 17 00:00:00 2001 From: bindoon Date: Tue, 8 Oct 2019 16:37:55 +0800 Subject: [PATCH] fix(Select): should not del disabled item with backspace. fix #1196 --- src/select/select.jsx | 9 ++++++++- test/select/index-spec.js | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/select/select.jsx b/src/select/select.jsx index 9a45c0ec56..79a95873ab 100644 --- a/src/select/select.jsx +++ b/src/select/select.jsx @@ -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 && diff --git a/test/select/index-spec.js b/test/select/index-spec.js index 8037b4584d..23e7dedafa 100644 --- a/test/select/index-spec.js +++ b/test/select/index-spec.js @@ -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',