fix: Improve focus handling when clicking outside injection div#9749
Merged
fix: Improve focus handling when clicking outside injection div#9749
Conversation
maribethb
reviewed
Apr 23, 2026
Contributor
Author
|
This also fixes #8868 |
maribethb
approved these changes
Apr 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The basics
The details
Resolves
Fixes RaspberryPiFoundation/blockly-keyboard-experimentation#563
Proposed Changes
This PR improves focus management when focus transitions out of the injection div, either via click or tab, while the
WidgetDiv,DropDownDiv, or both are open. Previously, this would get focus management into a bad wedged state. Now, theWidgetDiv/DropDownDiv(s) will be dismissed, the element that spawned them will get passive focus, and focus will transition to whatever the clicked/tabbed-to element is. When focus returns to the workspace, the element that spawned theWidgetDiv/DropDownDivwill regain active focus.At a high level, this works by:
focusoutevents on the div that holds theWidgetDiv/DropDownDivfocusoutevent is received, checks to make sure that the newly-focused element is actually outside of that divWidgetDivandDropDownDiv, which will (a) resign ephemeral focus if they hold it, while instructing the focus manager to not actively focus the previously-focused element, and (b) hide themselves*Divs, as focus moves around and the*Divs hide and show.I manually verified that this worked for dropdowns, menus, and field editors with a single playground and in the multi-playground, and also that behavior is as expected for
FieldAnglewhich uses both theDropDownDivand theWidgetDivsimultaneously. The latter will need some slight tweaks (in general, for fields that use both,WidgetDivshould take ephemeral focus in preference toDropDownDivso that the field editor is focused initially), but focus can move between the field editor and angle picker, both can be interacted with, and when the value is committed or focus leaves the workspace, the field becomes passively/actively focused as appropriate.I have not added unit tests because (a) it would be a pain but more importantly (b) it'd be very useful to make sure that this is robust and works for MakeCode given the previous churn that attempts to resolve this issue have caused before investing the effort to put together a test suite given point (a).