fix: improved refocus behavior on window exit and then return #2528
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 HTMLinput
ortextarea
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 windowblur
event rather than thevisibilitychange
event sincevisibilitychange
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 amathfield
). 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 theclick
event of document to cancel the refocus, this issue is corrected and now matches the normal HTMLinput
element behavior.This fix has been tested on Edge, Firefox, and Safari.
Previous focus behavior:
New focus behavior: