-
Notifications
You must be signed in to change notification settings - Fork 20.6k
Event: Simulate focus/blur in IE via focusin/focusout #5223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good for 4.0. We will not be guaranteeing order anymore, but #4300 points out that everyone has opinions on what the order should be and modern browsers don't even follow the spec.
b6be579
to
8cc5ff1
Compare
The |
ac380e3
to
3a1bd2d
Compare
@timmywil I added a few commits on top of the original PR so I'm re-requesting a review from you. |
7d67295
to
79daba0
Compare
this | ||
) | ||
} ); | ||
dataPriv.set( this, type, jQuery.event.trigger( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gibson042 One thing to note - while #4350 which added this wrapping was mainly aimed at IE with its async focus
handlers, there has been a report about this also affecting Chrome somehow:
#4350 (comment)
I'm not sure if we can do anything about it due to the lack of data, though.
79daba0
to
02906a8
Compare
02906a8
to
7022908
Compare
It looks like this also fixes #4950; I added a test for this in a separate commit & verified it fails on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏 👏 👏
This also seems to fix one heavily upvoted select2 issue: select2/select2#5993. |
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`.
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.
7022908
to
f5b7dc0
Compare
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. Asynchronous behavior of these handlers in IE caused issues for IE (gh-4856, gh-4859). We now simulate `focus` via `focusin` & `blur` via `focusout` in IE to avoid these issues. This also let us simplify some tests. This commit also simplifies `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`. This also fixes broken `focus` triggers after first triggering it on a hidden element - previously, `leverageNative` assumed that the native `focus` handler not firing after calling the native `focus` method meant it would be handled later, asynchronously, which was not the case (gh-4950). 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. Fixes gh-4856 Fixes gh-4859 Fixes gh-4950 Ref gh-5223 Closes gh-5224 Co-authored-by: Richard Gibson <richard.gibson@gmail.com>
Previously, when `leverageNative` handled async events, there was a case where an empty placeholder object was set as a result. Covering both such an object and `false` required a `length` check. However, this is not necessary since jquerygh-5223 and the check was already simplified in other places; this one was missed. Ref jquerygh-5223
Previously, when `leverageNative` handled async events, there was a case where an empty placeholder object was set as a result. Covering both such an object and `false` required a `length` check. However, this is not necessary since gh-5223 and the check was already simplified in other places; this one was missed. Closes gh-5236 Ref gh-5223
Previously, when `leverageNative` handled async events, there was a case where an empty placeholder object was set as a result. Covering both such an object and `false` required a `length` check. However, this is not necessary since gh-5223 and the check was already simplified in other places; this one was missed. Closes gh-5236 Ref gh-5223 (cherry picked from commit dfe212d)
Summary
In IE (all versions),
focus
&blur
handlers are fired asynchronouslybut
focusin
&focusout
are run synchronously. In other browsers, allthose handlers are fired synchronously.
Simulate
focus
viafocusin
&blur
viafocusout
in IE toavoid these issues.
Fixes gh-4856
Fixes gh-4859
Fixes gh-4950
+30 bytes
3.x-stable
version of this PR: #5224Checklist