Skip to content

fix(TrapFocus): don't refocus when another component intentionally moves focus#597

Open
egucciar wants to merge 1 commit intoreshaped-ui:canaryfrom
observeinc:trap-focus-return-focus-if-only-lost-to-body
Open

fix(TrapFocus): don't refocus when another component intentionally moves focus#597
egucciar wants to merge 1 commit intoreshaped-ui:canaryfrom
observeinc:trap-focus-return-focus-if-only-lost-to-body

Conversation

@egucciar
Copy link
Copy Markdown
Contributor

@egucciar egucciar commented Mar 9, 2026

Summary

The MutationObserver was forcibly pulling focus back into the flyout whenever a DOM mutation occurred while focus was outside the root. This broke external components (e.g. Radix Select) that render a portal and legitimately move focus out of the trap.

The observer's original intent is to recover from accidental focus loss caused by a focused element being removed from the DOM — in which case the browser resets activeElement to document.body. Adding a guard for this condition preserves that behavior while leaving intentional focus moves (activeElement is a real element) untouched.

Related Issue

#596

…ves focus

The MutationObserver was forcibly pulling focus back into the flyout
whenever a DOM mutation occurred while focus was outside the root.
This broke external components (e.g. Radix Select) that render a portal
and legitimately move focus out of the trap.

The observer's original intent is to recover from accidental focus loss
caused by a focused element being removed from the DOM — in which case
the browser resets activeElement to document.body. Adding a guard for
this condition preserves that behavior while leaving intentional focus
moves (activeElement is a real element) untouched.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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