diff --git a/src/BaseSelect/index.tsx b/src/BaseSelect/index.tsx index a2a15e8c..3eb15dfd 100644 --- a/src/BaseSelect/index.tsx +++ b/src/BaseSelect/index.tsx @@ -605,9 +605,15 @@ const BaseSelect = React.forwardRef((props, ref) onSearch(mergedSearchValue, { source: 'submit' }); } else if (mode === 'multiple') { // `multiple` mode only clean the search value but not trigger event - onSearch('', { - source: 'blur', - }); + if (mergedShowSearch) { + onSearch('', { + source: 'effect', + }); + } else { + onSearch('', { + source: 'blur', + }); + } } } diff --git a/tests/Select.test.tsx b/tests/Select.test.tsx index a37330dd..caca556c 100644 --- a/tests/Select.test.tsx +++ b/tests/Select.test.tsx @@ -605,6 +605,49 @@ describe('Select.Basic', () => { jest.useRealTimers(); }); + describe('should call handleSearch twice on search and blur', () => { + injectRunAllTimers(jest); + + beforeEach(() => { + jest.useFakeTimers(); + }); + + afterEach(() => { + jest.useRealTimers(); + }); + + it('multiple mode should call handleSearch twice on search and blur', async () => { + const handleSearch = jest.fn(); + const { container } = render( + , + ); + fireEvent.change(container.querySelector('input')!, { target: { value: '1' } }); + // 模拟失去焦点(blur)事件 + fireEvent.blur(container.querySelector('input')); + jest.runAllTimers(); + expect(handleSearch).toHaveBeenCalledTimes(2); + jest.useRealTimers(); + }); + + it('not multiple mode should call handleSearch twice on search and blur', async () => { + const handleSearch = jest.fn(); + const { container } = render( + , + ); + fireEvent.change(container.querySelector('input')!, { target: { value: '1' } }); + fireEvent.blur(container.querySelector('input')); + jest.runAllTimers(); + expect(handleSearch).toHaveBeenCalledTimes(2); + jest.useRealTimers(); + }); + }); + it('should render 0 as text properly', () => { const data = [ { text: 0, value: '=0' },