-
Notifications
You must be signed in to change notification settings - Fork 1k
fix: handle focus and keyboard navigation when components are used in shadow DOM #3674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
… shadow DOM boundary
…ross the shadow DOM boundary
…ss the shadow DOM boundary
…the shadow DOM boundary
|
ca85a26
to
897233e
Compare
- Add data-radix-menu-sub-trigger attribute to MenuSubTrigger for proper identification - Implement custom event system for explicit submenu closure in shadow DOM contexts - Disable automatic grace timer closure in shadow DOM to prevent premature submenu closing - Use native event coordinates for improved accuracy in shadow DOM environments - Extend grace period to 800ms in shadow DOM to account for coordinate detection limitations - Ensure only one submenu remains open when navigating between multiple subtriggers 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Remove unnecessary empty lines and unused variables - Extract shadow DOM detection into reusable utility function - Simplify coordinate handling by removing unused adjustments - Revert isPointerInGraceArea changes that weren't needed for the fix - Reduce code duplication in shadow DOM detection logic 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
970ef4c
to
b9126cc
Compare
… DOM The logic was unnecessary, and infact, was incorrect, as it was running when _not_ in a shadow DOM
This pull request introduces comprehensive improvements to focus management across several Radix UI packages, with a particular emphasis on supporting Shadow DOM scenarios. The main enhancement is the addition and integration of the
getDeepActiveElement
utility, which reliably retrieves the currently focused element even when focus is within a shadow root. This change ensures consistent and predictable focus behavior for components rendered inside Shadow DOM, and also introduces new logic for menu and submenu interactions in these contexts.Focus Management Enhancements:
getDeepActiveElement
utility to@radix-ui/primitive
, enabling accurate retrieval of the focused element across Shadow DOM boundaries.document.activeElement
withgetDeepActiveElement
in@radix-ui/react-focus-scope
,@radix-ui/react-menu
,@radix-ui/react-navigation-menu
, and@radix-ui/react-one-time-password-field
, ensuring robust focus detection and handling in Shadow DOM environments. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13]Menu and Submenu Shadow DOM Support:
@radix-ui/react-menu
to force-close other submenus when entering any menu item within Shadow DOM, using a custom bubbling event (radix-force-close-submenu
). This prevents unintended multiple submenus from remaining open. [1] [2]MenuSubTrigger
to listen for the custom close event and conditionally close submenus, excluding the currently hovered trigger.Utilities and Dependency Updates:
@radix-ui/primitive
as a dependency to@radix-ui/react-focus-scope
to support the new utility function.isInShadowDOM
utility to detect if an element is inside a Shadow DOM, used to trigger adjusted menu behaviors.These changes collectively improve focus management reliability and menu interaction consistency, especially for applications leveraging Shadow DOM for encapsulation.
Fixes #3287
Fixes #3353
Fixes #2606