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
Focus Management within Shadow DOM #6046
base: main
Are you sure you want to change the base?
Focus Management within Shadow DOM #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. |
You'll need to sign the Adobe CLA and then close and reopen this PR for the it to pass. But also I'd like to let you know that we might be slow to review as we work through some other priorities and we apologize for the wait. |
…getOwnerDocument` used to handle.
This is a great contribution, and it would be very useful for our team to see Shadow DOM support in React Spectrum. I've had a play with it, and can see it works for some components, however it seems to not work with all overlays (AlertDialog, ContextualHelp, ActionMenu, Picker, etc.). There are a couple of issues, including that after closing the overlay, focus is not returned correctly to the element that triggered the open, and there also seems to be some state bug too where it thinks the overlay is still open. See this screen recording for an example with Picker - you will see that focus is not returned after choosing a value, and the Picker trigger still looks "pressed": I tried modifying I've not had too much of a dig around, but I can see there are quite a lot of uses of |
Thanks, @davidferguson, for looking at the PR; what you mentioned is really helpful, and finding the correct I will try to invest some time soon to fix the overlays raised issues and the state issue; most likely the overlay issues will share the same root cause. |
Hi @MahmoudElsayad, I did spend some time looking into this, and fixing it for the use cases that we needed. I'm attaching a patch file in the hope it may be useful for you. This is based off 3.34.1, so not the current main, or your PR, but it should be similar to apply. It makes overlays (menus, dialogs) and toasts and landmarks functional for our use case. @yihuiliao and @snowystinger, is there a preferred approach of how you'd like to see webcomponent & React Spectrum support progress? Is working on small individual fixes like @MahmoudElsayad's work, and now my overlay work the way forward, or are you hoping for a more holistic, comprehensive approach that updates the entire library at once? |
@davidferguson Thank you for the patch! I think the way to go would be in small individual fixes; it will be great if you open a PR for the patch changes as well, and you can branch off this PR if you find any useful utility that can be used and that way, we add support incrementally for shadow DOM. @yihuiliao and @snowystinger, Your feedback would be greatly appreciated to move things forward. |
@davidferguson One issue related to overlays, which I don't know if you have encountered yet or not, and that arose from accessibility testing, is that the It's been handled in #6133; I am working on it getting the PR ready for review as well. |
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 -