Skip to content

Commit 22dad3b

Browse files
authored
fix[Select]: fix select losing focus issue (#7829)
1 parent 4f7bd6f commit 22dad3b

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

Diff for: components/select/__tests__/index.test.js

+46
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,52 @@ describe('Select', () => {
159159
}, 500);
160160
});
161161

162+
it('The select trigger should be blur when the panel is closed.', async () => {
163+
const wrapper = mount(
164+
{
165+
render() {
166+
return (
167+
<Select
168+
dropdownRender={() => {
169+
return <input id="dropdownRenderInput" />;
170+
}}
171+
/>
172+
);
173+
},
174+
},
175+
{
176+
sync: false,
177+
attachTo: 'body',
178+
},
179+
);
180+
await asyncExpect(async () => {
181+
await wrapper.find('.ant-select-selector').trigger('mousedown');
182+
await wrapper.find('.ant-select-selection-search-input').trigger('focus');
183+
});
184+
185+
await asyncExpect(async () => {
186+
const el = wrapper.find('.ant-select');
187+
188+
expect(el.classes()).toContain('ant-select-focused');
189+
$$('#dropdownRenderInput')[0].focus();
190+
191+
expect(el.classes()).toContain('ant-select-focused');
192+
193+
document.body.dispatchEvent(
194+
new MouseEvent('mousedown', {
195+
bubbles: true,
196+
cancelable: true,
197+
view: window,
198+
}),
199+
);
200+
}, 100);
201+
202+
await asyncExpect(async () => {
203+
const el = wrapper.find('.ant-select');
204+
expect(el.classes()).not.toContain('ant-select-focused');
205+
}, 200);
206+
});
207+
162208
describe('Select Custom Icons', () => {
163209
it('should support customized icons', () => {
164210
const wrapper = mount({

Diff for: components/vc-select/BaseSelect.tsx

+8
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,14 @@ export default defineComponent({
343343
if (mergedOpen.value !== nextOpen && !props.disabled) {
344344
setInnerOpen(nextOpen);
345345
props.onDropdownVisibleChange && props.onDropdownVisibleChange(nextOpen);
346+
347+
if (!nextOpen && popupFocused.value) {
348+
popupFocused.value = false;
349+
setMockFocused(false, () => {
350+
focusRef.value = false;
351+
blurRef.value = false;
352+
});
353+
}
346354
}
347355
};
348356

0 commit comments

Comments
 (0)