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

fix: improved refocus behavior on window exit and then return #2528

Merged
merged 1 commit into from
Sep 27, 2024

Conversation

mgreminger
Copy link
Contributor

This pull request fixes two issues with focus handling when switching away from and back to a tab with a mathfield element to make the behavior the same as a standard HTML input or textarea element. The current behavior is correct when switching tabs (the first test in the two videos below) but doesn't correctly handle the case when switching non-overlapping windows (second test in the two videos below). This was corrected by looking for the window blur event rather than the visibilitychange event since visibilitychange is not triggered when switching windows that are not overlapping.

The second issue that is addressed is correctly handling the case where the user clicks off of the mathfield element but doesn't select another element (third test in the videos below, users commonly do this to unselect a mathfield). Previously, the mathfield would incorrectly regain focus when the tab is refocused even though the mathfield wasn't previously focused. This behavior is confusing to users and may cause unintentional scrolling if the user has scrolled the mathfield out of view (this may be related to the issues raised in #2337). By using the click event of document to cancel the refocus, this issue is corrected and now matches the normal HTML input element behavior.

This fix has been tested on Edge, Firefox, and Safari.

Previous focus behavior:
Previous focus behavior screen capture video

New focus behavior:
New focus behavior screen capture video

Now correctly handles case where window is still visible (previoulsy only work when tab was entirely hidden). Additionaly, a click off of the math field will now cancel the refocus similar to a standard input element.
@arnog
Copy link
Owner

arnog commented Sep 27, 2024

Thanks for investigating this issue and providing a PR. LGTM. I'll investigate the Playwright failures.

@arnog arnog merged commit 395a51a into arnog:master Sep 27, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants