🌐 AI搜索 & 代理 主页
Skip to content

Conversation

@mgol
Copy link
Member

@mgol mgol commented Mar 13, 2023

Summary

In IE (all versions), focus & blur handlers are fired asynchronously
but focusin & focusout are run synchronously. In other browsers, all
those handlers are fired synchronously.

Simulate focus via focusin & blur via focusout in IE to
avoid these issues.

Also, simplify leverageNative - With IE now using focusin to simulate
focus and focusout to simulate blur, we don't have to deal with
async events in leverageNative.

Fixes gh-4856
Fixes gh-4859
Fixes gh-4950

+58 bytes

All tests are passing in IE 9-11, I verified manually.

main (4.x) version of this PR: #5223

Checklist

  • New tests have been added to show the fix or feature works
  • Grunt build and unit tests pass locally with these changes
  • If needed, a docs issue/PR was created at https://github.com/jquery/api.jquery.com

@mgol mgol added this to the 3.7.0 milestone Mar 13, 2023
@mgol mgol self-assigned this Mar 13, 2023
@mgol
Copy link
Member Author

mgol commented Mar 13, 2023

The main version of the PR: #5223.

@mgol mgol requested review from dmethvin, gibson042 and timmywil March 13, 2023 23:58
@mgol mgol force-pushed the 3.x-ie-focus-simulation branch from 49d2e2d to c052f78 Compare March 14, 2023 00:03
@mgol mgol changed the title Event: Simulate focus/blur in IE via focusin/focusout Event: Simulate focus/blur in IE via focusin/focusout (3.x version) Mar 14, 2023
@mgol mgol force-pushed the 3.x-ie-focus-simulation branch 7 times, most recently from d4e0cf8 to 9952fdc Compare March 17, 2023 09:42
@mgol
Copy link
Member Author

mgol commented Mar 17, 2023

It looks like this also fixes #4950; I added a test for this in a separate commit & verified it fails on 3.x-stable.

@mgol
Copy link
Member Author

mgol commented Mar 17, 2023

This also seems to fix one heavily upvoted select2 issue: select2/select2#5993.

mgol and others added 6 commits March 21, 2023 00:51
In IE (all versions), `focus` & `blur` handlers are fired asynchronously
but `focusin` & `focusout` are run synchronously. In other browsers, all
those handlers are fired synchronously.

Simulate `focus` via `focusin` & `blur` via `focusout` in IE to
avoid these issues.

Fixes jquerygh-4856
Fixes jquerygh-4859
Fixes jquerygh-4950
Tests added:
* sequences triggering focus and/or blur (authored by Richard Gibson)
* focus does not bubble
* some test stability fixes

Co-authored-by: Richard Gibson <richard.gibson@gmail.com>
With IE now using `focusin` to simulate `focus` and `focusout`
to simulate `blur`, we don't have to deal with async events
in leverageNative.
To preserve relative focusin/focus & focusout/blur event order guaranteed
on the 3.x branch, attach a single handler for both events in IE.

A side effect of this is that to reduce size the `event/focusin` module
no longer exists and it's impossible to disable the focusin patch
in modern browsers via the jQuery custom build system.
Now that jQuery focus/blur events in IE are not async, we can
simplify some tests.
Focusing an input with `display: none` no longer prevents it from
being focused when it gets shown later.
@mgol mgol force-pushed the 3.x-ie-focus-simulation branch from 9952fdc to fd2653b Compare March 20, 2023 23:51
@mgol mgol removed the Needs review label Mar 27, 2023
@mgol mgol merged commit 59f7b55 into jquery:3.x-stable Mar 27, 2023
@mgol mgol deleted the 3.x-ie-focus-simulation branch March 27, 2023 19:24
mgol added a commit to mgol/jquery that referenced this pull request Apr 3, 2023
There was a comment claiming that there are two implementations
of `safeActiveElement`. However, the one in `event.js` got removed
in jquerygh-5224, even before the comment was added.

This commit removes this obsolete comment.

Ref jquerygh-5224
@mgol mgol mentioned this pull request Apr 3, 2023
1 task
mgol added a commit that referenced this pull request Apr 3, 2023
There was a comment claiming that there are two implementations
of `safeActiveElement`. However, the one in `event.js` got removed
in gh-5224, even before the comment was added.

This commit removes this obsolete comment.

Closes gh-5237
Ref gh-5224
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Development

Successfully merging this pull request may close these issues.

3 participants