diff --git a/src/Selector/MultipleSelector.tsx b/src/Selector/MultipleSelector.tsx index 02c5b823c..df0eef8ce 100644 --- a/src/Selector/MultipleSelector.tsx +++ b/src/Selector/MultipleSelector.tsx @@ -132,7 +132,7 @@ const SelectSelector: React.FC = props => { > {({ key, label, value, disabled: itemDisabled, className, style }) => { const mergedKey = key || value; - const closable = key !== REST_TAG_KEY && !itemDisabled; + const closable = !disabled && key !== REST_TAG_KEY && !itemDisabled; const onMouseDown = (event: React.MouseEvent) => { event.preventDefault(); event.stopPropagation(); diff --git a/tests/Tags.test.tsx b/tests/Tags.test.tsx index 8c2a8186d..d2a1b9603 100644 --- a/tests/Tags.test.tsx +++ b/tests/Tags.test.tsx @@ -1,3 +1,4 @@ +/* eslint-disable import/no-named-as-default-member */ import { mount } from 'enzyme'; import KeyCode from 'rc-util/lib/KeyCode'; import classNames from 'classnames'; @@ -268,26 +269,58 @@ describe('Select.Tags', () => { expect(onChange).toHaveBeenCalledWith(['a'], expect.anything()); }); - it('can render custom tags', () => { - const onTagRender = jest.fn(); - const tagRender = (props: any) => { - const { label } = props; - onTagRender(label); - return ( - - {label} - {label} - + describe('tagRender', () => { + it('can render custom tags', () => { + const onTagRender = jest.fn(); + const tagRender = (props: any) => { + const { label } = props; + onTagRender(label); + return ( + + {label} + {label} + + ); + }; + const wrapper = mount(, ); - }; - const wrapper = mount(, + ); + + expect(tagRender).toHaveBeenCalledWith(expect.objectContaining({ closable: false })); + }); }); describe('OptGroup', () => { @@ -326,12 +359,14 @@ describe('Select.Tags', () => { }); it('should work fine when filterOption function exists', () => { + const LegacyOption = Select.Option as any; // Compatible to legacy usage + const children = []; for (let i = 10; i < 36; i += 1) { children.push( - , + , ); } const wrapper = mount( diff --git a/tests/shared/removeSelectedTest.tsx b/tests/shared/removeSelectedTest.tsx index ba4abec55..b9da6b5f0 100644 --- a/tests/shared/removeSelectedTest.tsx +++ b/tests/shared/removeSelectedTest.tsx @@ -34,17 +34,15 @@ export default function removeSelectedTest(mode: any) { value={['1']} onChange={handleChange} onDeselect={handleDeselect} - disabled={true} + disabled mode={mode} > , ); - removeSelection(wrapper); - expect(handleDeselect).not.toHaveBeenCalled(); - expect(handleChange).not.toHaveBeenCalled(); + expect(wrapper.find('.rc-select-selection-item-remove')).toHaveLength(0); }); it('wrap value when labelInValue', () => { @@ -55,7 +53,7 @@ export default function removeSelectedTest(mode: any) { value={[{ key: '1' }, { key: '2' }]} onChange={handleChange} onDeselect={handleDeselect} - labelInValue={true} + labelInValue mode={mode} >