Skip to content

Commit aa40e46

Browse files
committed
🐛 Fix select mode="multiple onFocus not triggered in IE
close ant-design/ant-design#15942
1 parent f478625 commit aa40e46

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/Select.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,19 @@ class Select extends React.Component<Partial<ISelectProps>, ISelectState> {
506506
return;
507507
}
508508
this.clearBlurTime();
509-
if (!isMultipleOrTagsOrCombobox(this.props) && e.target === this.getInputDOMNode()) {
509+
510+
// In IE11, onOuterFocus will be trigger twice when focus input
511+
// First one: e.target is div
512+
// Second one: e.target is input
513+
// other browser only trigger second one
514+
// https://github.com/ant-design/ant-design/issues/15942
515+
// Here we ignore the first one when e.target is div
516+
const inputNode = this.getInputDOMNode();
517+
if (inputNode && e.target === this.rootRef) {
518+
return;
519+
}
520+
521+
if (!isMultipleOrTagsOrCombobox(this.props) && e.target === inputNode) {
510522
return;
511523
}
512524
if (this._focused) {

tests/Select.multiple.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ describe('Select.multiple', () => {
9191
</Select>,
9292
);
9393
jest.useFakeTimers();
94-
wrapper.find('.rc-select').simulate('focus');
94+
wrapper.find('input').simulate('focus');
9595
jest.runAllTimers();
9696
expect(handleFocus).toBeCalled();
9797
});

tests/Select.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ describe('Select', () => {
435435
beforeEach(() => {
436436
handleFocus = jest.fn();
437437
wrapper = mount<Select>(
438-
<Select onFocus={handleFocus}>
438+
<Select onFocus={handleFocus} showSearch={false}>
439439
<Option value="1">1</Option>
440440
<Option value="2">2</Option>
441441
</Select>,

0 commit comments

Comments
 (0)