-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat: Focus Management within ShadowDOM #6046
feat: Focus Management within ShadowDOM #6046
Conversation
Update domHelpers.test.js.
Add Tests for FocusScope.test.js. New helper util `getRootBody`.
Fix `useRestoreFocus` issue. Add new DOM util `getDeepActiveElement`.
… navigation example`.
update `useFocus` - `useFocusWithin` - `usePress`.
Test for `focusSafely`.
@snowystinger We are working on fixing the linting and type errors but if you want you can give an early eye to this PR. |
# Conflicts: # packages/@react-aria/focus/src/FocusScope.tsx
perf and size comments on PR #7548 (comment) |
80daa95
to
21b80bd
Compare
# Conflicts: # packages/@react-aria/focus/src/FocusScope.tsx # packages/@react-aria/interactions/src/usePress.ts # packages/@react-aria/interactions/test/usePress.test.js # packages/@react-spectrum/table/test/Table.test.js
@snowystinger These changes look good so far. Our internal tests are passing. We will be opening some small followup PRs too once this gets merged. Any idea about the timeline for this PR ? |
Thanks for checking in, we are still in discussions internally. Should have more information for you early next week. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this. I appreciate the persistence, and I know it's been a long process.
In the future, I think we may need to revisit how some of our components are implemented more holistically to account for shadow dom. While deeply traversing into shadow roots works in some cases, it won't work with closed shadow roots. For example, even with the FocusScope changes here, things like native <video>
elements, <input type="date">
, etc., along with any third party components using closed shadow roots will still not work correctly since we cannot traverse into them. Fixing that would require a completely different implementation strategy.
Overall, shadow dom is meant to encapsulate behavior, and deep traversal sort of goes against that goal. For now it's better than nothing, but it would be good to try to find ways to avoid it in the future if possible.
dc4ca82
Thanks again, this will be available in our nightlies starting tonight. You can enable the behavior using the feature flag.
As @devongovett noted, we're starting to think about how we want to move forward with this kind of work. We've made a start here: #7687 |
Closes #1472
This PR enhances focus management capabilities in React Spectrum applications when used within Shadow DOM environments.
Changes
getRootNode
, designed to return a given element's contextually appropriate root (Document or ShadowRoot). This improves the library's ability to query and manipulate focus within shadow DOMs.FocusScope
useFocus
useFocusVisible
useFocusWithin
useInteractionOutside
usePress
getRootBody
that determines the effective "body" element for an event's propagation path, supporting both Shadow DOM and traditional document structures.✅ Pull Request Checklist:
📝 Test Instructions:
🧢 Your Project:
PSPDFKit -![](https://camo.githubusercontent.com/8ab1f45351d092507cbda2f6fcbd6c622cb3b5754e908374f974666ab95ab630/68747470733a2f2f70737064666b69742e636f6d2f6173736574732f696d616765732f6c6f676f732f70737064666b69742d33636364383235332e737667)