Skip to content

fix(modal): prevent focus from being placed on modal container#772

Merged
huyenltnguyen merged 1 commit intofreeCodeCamp:mainfrom
huyenltnguyen:fix/initial-focus
Apr 26, 2026
Merged

fix(modal): prevent focus from being placed on modal container#772
huyenltnguyen merged 1 commit intofreeCodeCamp:mainfrom
huyenltnguyen:fix/initial-focus

Conversation

@huyenltnguyen
Copy link
Copy Markdown
Member

@huyenltnguyen huyenltnguyen commented Apr 26, 2026

Checklist:

Related to freeCodeCamp/freeCodeCamp#66639.

I have not been able to reproduce the issue, so I think this is a race condition.

Likely cause:

  • When a modal opens, showFocusRingOnInitialFocus runs via HeadlessUI's afterEnter callback and applies an inline outline style to whatever document.activeElement is at that moment.
  • document.activeElement might be the <Dialog> wrapper element itself, so it could receive the blue outline. Since this is a full-viewport fixed element, the blue lines appear at the viewport edges.
  • The outline then persists because the element may be removed from the DOM before a blur event fires, so the once: true cleanup listener never runs.

The fix is to guard against applying an outline to body, html, or the dialog container (role="dialog").

@huyenltnguyen huyenltnguyen marked this pull request as ready for review April 26, 2026 20:17
@huyenltnguyen huyenltnguyen requested a review from a team as a code owner April 26, 2026 20:17
@huyenltnguyen huyenltnguyen merged commit 00d5cbc into freeCodeCamp:main Apr 26, 2026
7 checks passed
@huyenltnguyen huyenltnguyen deleted the fix/initial-focus branch April 26, 2026 20:56
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.

1 participant