Fix comment input losing focus inside host-app modals (focus trap)#46
Open
sacrezm wants to merge 1 commit into
Open
Fix comment input losing focus inside host-app modals (focus trap)#46sacrezm wants to merge 1 commit into
sacrezm wants to merge 1 commit into
Conversation
Host-app modals with a focus trap (Radix Dialog / focus-lock) reclaim focus whenever it leaves their subtree. Drawbridge injects its comment <textarea> at <body> level (light DOM), so the trap steals focus the instant you click the comment box and you can't type a note. Add a capture-phase focusin/focusout guard that stops propagation for focus events originating inside Drawbridge nodes ([id^="moat-"],[class*="moat"],[class*="float-comment"]). Capture runs before the app's bubble-phase handler, so the trap never sees focus leave; only Drawbridge-originated focus events are stopped, leaving the app's own focus behavior untouched.
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.
Problem
When you annotate an element that lives inside a host-app modal, the Drawbridge comment box appears but won't accept any text — you can't type the note.
Cause
Many apps render modals with a focus trap (e.g. Radix Dialog /
@radix-ui/react-focus-scope, focus-lock). On everyfocusinthat leaves the dialog subtree, the trap reclaims focus. Drawbridge injects its comment<textarea>(.float-comment-input) at<body>level in the light DOM, so from the modal's perspective the textarea is "outside" the dialog — the trap steals focus back the instant you click it, and typing is impossible.Fix
Register a capture-phase
focusin/focusoutguard once at content-script load that callsstopImmediatePropagation()for focus events whose target is inside a Drawbridge node ([id^="moat-"],[class*="moat"],[class*="float-comment"]).Capture phase runs before the app's bubble-phase
focusinhandler, so the trap never sees focus leave the dialog and the textarea keeps focus. Only Drawbridge-originated focus events are stopped, so the host app's own focus behavior is untouched, and click/submit handlers (different event types) are unaffected.Test plan
C, click an element inside it, and type in the comment box.