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

Use native focus events insted of jQuery focus events #163

Merged
merged 1 commit into from
Nov 12, 2021
Merged

Conversation

jwmerrill
Copy link
Member

@jwmerrill jwmerrill commented 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:

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 calling the native DOM .focus() method instead of the jQuery .focus() method.

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.
Copy link

@sclower sclower left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this update. I have confirmed it fixes the focus problems with JQuery 3.6.0.

@jwmerrill jwmerrill merged commit 7612cc5 into main Nov 12, 2021
@jwmerrill
Copy link
Member Author

I got a little anxious (partly based on a StackOverflow answer) that the native .focus() method might cause different events to fire, either on the element that's being focused or on its parents, and either native and/or jquery events.

I set up a JSBin to test this (using the latest stable jQuery version: 3.6.0), and as far as I could determine, this is not the case.

Native programmatic focus: https://jsbin.com/cimidid/5
jQuery programmatic focus: https://jsbin.com/cimidid/7
Manual focus: https://jsbin.com/cimidid/8

I tested these in Firefox 95, Chrome 96, and Safari 15.0 on macOS 11.6, and all of them produce the same events and order:

jQuery focusin fired on input
jQuery focusin fired on container
native focus fired on input
jQuery focus fired on input
native focusin fired on input
native focusin fired on container

I also tested these in IE 11 on windows 10 (through browserstack), and all 3 of them produced the same events, in a consistent but different order from other browsers

native focusin fired on input
jQuery focusin fired on input
native focusin fired on container
jQuery focusin fired on container
native focus fired on input
jQuery focus fired on input

Based on these tests, I now think this change should actually be pretty safe to make, and should be unlikely to change typical observable behaviors of focusing mathquill elements (except to fix the intended bug).

Copy link

@22aam 22aam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all of the code looks good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants