Skip to content
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

In jQuery 3.4.0+ in IE a focus-blur-focus sequence doesn't leave the element focused #4856

Closed
mgol opened this issue Mar 10, 2021 · 5 comments · Fixed by #5223
Closed

In jQuery 3.4.0+ in IE a focus-blur-focus sequence doesn't leave the element focused #4856

mgol opened this issue Mar 10, 2021 · 5 comments · Fixed by #5223
Assignees
Milestone

Comments

@mgol
Copy link
Member

mgol commented Mar 10, 2021

Description

Invoking:

$( inputNode )
	.trigger( "focus" )
	.trigger( "blur" )
	.trigger( "focus" );

leaves input focused in all browsers except IE.

I discovered it while working to fix the remaining jQuery UI issues when tested against Core 3.6.0+. Interestingly, the relevant UI issue doesn't manifest itself in 3.4 & 3.5, I'm not sure why.

A relevant UI test run: http://swarm.jquery.org/result/3963629. That's the "dialog: core: focus tabbable" test.

Link to test case

https://jsbin.com/zoyowez/1/edit?html,js,output

Changing the jQuery version to 3.3.1 makes it work again.

@mgol mgol added Bug Event Discuss in Meeting Reserved for Issues and PRs that anyone would like to discuss in the weekly meeting. labels Mar 10, 2021
@mgol
Copy link
Member Author

mgol commented Mar 11, 2021

OK, the relevant UI test (dialog: core: focus tabbable):
https://builds.jenkins.jquery.com/jquery-ui/9ea690a0d9e645280dbb448579d2ac3babb510ed/tests/unit/dialog/dialog.html?nojshint=true&jquery=3.4.1&testId=a84fb0fe
does fail with jQuery 3.4+, it's just that in 3.4 & 3.5 it doesn't fail when run together with the rest of the dialog test suite.

@mgol
Copy link
Member Author

mgol commented Mar 11, 2021

mgol added a commit to mgol/jquery-ui that referenced this issue Mar 11, 2021
In IE in jQuery 3.4+ a sequence:
```js
$( inputNode ).trigger( "focus" ).trigger( "blur" ).trigger( "focus" );
```
doesn't end up with a focused input. However, in this test we only want to check
that the last focusedinput receives the focus back when `_focusTabbable()` is
called which in reality doesn't happen so quickly so let's avoid the issue by
waiting a bit.

Ref jquery/jquery#4856
mgol added a commit to mgol/jquery-ui that referenced this issue Mar 14, 2021
In IE in jQuery 3.4+ a sequence:
```js
$( inputNode ).trigger( "focus" ).trigger( "blur" ).trigger( "focus" );
```
doesn't end up with a focused input. However, in this test we only want to check
that the last focused input receives the focus back when `_focusTabbable()` is
called which in reality doesn't happen so quickly so let's avoid the issue by
waiting a bit.

Ref jquery/jquery#4856
@timmywil timmywil added this to the 3.6.1 milestone Mar 15, 2021
@timmywil timmywil removed the Discuss in Meeting Reserved for Issues and PRs that anyone would like to discuss in the weekly meeting. label Mar 15, 2021
@timmywil
Copy link
Member

We'll look at addressing focus issues in 3.6.1.

mgol added a commit to jquery/jquery-ui that referenced this issue Mar 16, 2021
In IE in jQuery 3.4+ a sequence:
```js
$( inputNode ).trigger( "focus" ).trigger( "blur" ).trigger( "focus" );
```
doesn't end up with a focused input. However, in this test we only want to check
that the last focused input receives the focus back when `_focusTabbable()` is
called which in reality doesn't happen so quickly so let's avoid the issue by
waiting a bit.

Ref jquery/jquery#4856
Closes gh-1951
@mgol mgol added the Blocker label Mar 22, 2021
gibson042 added a commit to gibson042/jquery that referenced this issue Jun 11, 2021
jwmerrill added a commit to desmosinc/mathquill that referenced this issue Nov 12, 2021
jQuery 3.x has introduced a bunch of different focus bugs in the process
of attempting to migrate to using native focus events in more cases,
some of which remain unfixed in the latest version (3.6.0).

Examples:
* jquery/jquery#4859
* jquery/jquery#4856
* jquery/jquery#4950
* jquery/jquery#4867

Some unknown bug in this general class can make it so that Mathquill
public api focus calls stop working because using jQuery to
programatically trigger focus breaks.

Work around this by switching to triggering native focus events instead
of jQuery focus events.
jwmerrill added a commit to desmosinc/mathquill that referenced this issue Nov 16, 2021
jQuery 3.x has introduced a bunch of different focus bugs in the process
of attempting to migrate to using native focus events in more cases,
some of which remain unfixed in the latest version (3.6.0).

Examples:
* jquery/jquery#4859
* jquery/jquery#4856
* jquery/jquery#4950
* jquery/jquery#4867

Some unknown bug in this general class can make it so that Mathquill
public api focus calls stop working because using jQuery to
programatically trigger focus breaks.

Work around this by switching to triggering native focus events instead
of jQuery focus events.
gibson042 added a commit to gibson042/jquery that referenced this issue Jan 24, 2022
@timmywil timmywil modified the milestones: 3.6.1, 3.7.0 Aug 15, 2022
mgol added a commit to mgol/jquery that referenced this issue Mar 13, 2023
In IE (all versions), `focus` & `blur` handlers are fired asynchronously
but `focusin` & `focusout` are run synchronouslu. 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 jquerygh-4856
Fixes jquerygh-4859
mgol added a commit to mgol/jquery that referenced this issue Mar 13, 2023
In IE (all versions), `focus` & `blur` handlers are fired asynchronously
but `focusin` & `focusout` are run synchronouslu. 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
mgol added a commit to mgol/jquery that referenced this issue Mar 14, 2023
In IE (all versions), `focus` & `blur` handlers are fired asynchronously
but `focusin` & `focusout` are run synchronouslu. 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
@mgol
Copy link
Member Author

mgol commented Mar 14, 2023

It looks like we can fix this via simulating the async focus & blur in IE via their bubbling but also synchronous equivalents: focusin & focusout. In other browsers, all those events are synchronous.

PRs for:

@mgol mgol self-assigned this Mar 14, 2023
mgol added a commit to mgol/jquery that referenced this issue Mar 14, 2023
In IE (all versions), `focus` & `blur` handlers are fired asynchronously
but `focusin` & `focusout` are run synchronouslu. 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
mgol added a commit to mgol/jquery that referenced this issue Mar 14, 2023
In IE (all versions), `focus` & `blur` handlers are fired asynchronously
but `focusin` & `focusout` are run synchronouslu. 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
mgol added a commit to mgol/jquery that referenced this issue Mar 14, 2023
In IE (all versions), `focus` & `blur` handlers are fired asynchronously
but `focusin` & `focusout` are run synchronouslu. 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
mgol added a commit to mgol/jquery that referenced this issue Mar 14, 2023
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
mgol added a commit to mgol/jquery that referenced this issue Mar 14, 2023
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
mgol added a commit to mgol/jquery that referenced this issue Mar 15, 2023
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
mgol added a commit to mgol/jquery that referenced this issue Mar 15, 2023
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
mgol added a commit to mgol/jquery that referenced this issue Mar 17, 2023
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
mgol added a commit to mgol/jquery that referenced this issue Mar 17, 2023
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
mgol added a commit to mgol/jquery that referenced this issue Mar 20, 2023
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
mgol added a commit to mgol/jquery that referenced this issue Mar 20, 2023
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
mgol added a commit that referenced this issue Mar 27, 2023
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).

Fixes gh-4856
Fixes gh-4859
Fixes gh-4950
Closes gh-5223

Co-authored-by: Richard Gibson <richard.gibson@gmail.com>
mgol added a commit that referenced this issue Mar 27, 2023
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>
@mgol
Copy link
Member Author

mgol commented Mar 27, 2023

Fixed on main (future 4.x) via #5223 and on 3.x-stable via #5224.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment