Skip to content

Commit c4fd947

Browse files
committed
fix: onBlur should trigger blur when mode is null
1 parent a47fa76 commit c4fd947

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

src/BaseSelect/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
435435

436436
if (onSearch && mergedSearchValue !== newSearchText) {
437437
onSearch(newSearchText, {
438-
source: fromTyping ? 'typing' : mergedShowSearch ? 'blur' : 'effect',
438+
source: fromTyping ? 'typing' : 'effect',
439439
});
440440
}
441441

@@ -455,7 +455,7 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
455455

456456
// Close will clean up single mode search text
457457
React.useEffect(() => {
458-
if (!mergedOpen && !multiple && mode !== 'combobox') {
458+
if (!mergedOpen && !multiple && mode && mode !== 'combobox') {
459459
onInternalSearch('', false, false);
460460
}
461461
}, [mergedOpen]);
@@ -603,7 +603,7 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
603603
// `tags` mode should move `searchValue` into values
604604
if (mode === 'tags') {
605605
onSearch(mergedSearchValue, { source: 'submit' });
606-
} else if (mode === 'multiple') {
606+
} else if (!mode || mode === 'multiple') {
607607
// `multiple` mode only clean the search value but not trigger event
608608
onSearch('', {
609609
source: 'blur',

tests/BaseSelect.test.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ describe('BaseSelect', () => {
125125
});
126126

127127
describe("Testing BaseSelect component's onContainerBlur params", () => {
128-
it('mode with null, onContainerBlur params is blur', () => {
128+
it('mode with null, onBlur source is blur', () => {
129129
const onSearch = jest.fn();
130130
const { container } = render(
131131
<BaseSelect
@@ -135,7 +135,6 @@ describe('BaseSelect', () => {
135135
onDisplayValuesChange={() => {}}
136136
searchValue="1"
137137
showSearch
138-
open
139138
onSearch={onSearch}
140139
OptionList={OptionList}
141140
emptyOptions
@@ -148,7 +147,7 @@ describe('BaseSelect', () => {
148147
expect(onSearch).toHaveBeenCalledWith('', { source: 'blur' });
149148
});
150149

151-
it('mode with multiple, onContainerBlur params is blur', () => {
150+
it('mode with multiple, onBlur source is blur', () => {
152151
const onSearch = jest.fn();
153152
const { container } = render(
154153
<BaseSelect
@@ -159,7 +158,6 @@ describe('BaseSelect', () => {
159158
onDisplayValuesChange={() => {}}
160159
searchValue="1"
161160
showSearch
162-
open
163161
onSearch={onSearch}
164162
OptionList={OptionList}
165163
emptyOptions

tests/Select.test.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,13 @@ describe('Select.Basic', () => {
595595
selectItem(container);
596596
expect(handleSearch).toHaveBeenCalledTimes(1);
597597

598+
// Should not trigger onBlur
599+
fireEvent.change(container.querySelector('input'), { target: { value: '3' } });
600+
expect(handleSearch).toHaveBeenCalledTimes(2);
601+
fireEvent.blur(container.querySelector('input'));
602+
jest.runAllTimers();
603+
expect(handleSearch).toHaveBeenCalledTimes(2);
604+
598605
jest.useRealTimers();
599606
});
600607

0 commit comments

Comments
 (0)