Skip to content

[Dialog & AlertDialog] fix: can't get id correctly in shadow dom #3384

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

molvqingtai
Copy link

@molvqingtai molvqingtai commented Feb 16, 2025

Description

Using document.getElementById in Shadow DOM contexts will fail to access encapsulated elements. The correct approach is to query the element by ID from the parent DialogContent container instead.

fixed #3484
#2986 (comment)

@dylnslck
Copy link

Getting this merged in would be amazing.

@peguimasid
Copy link

This PR would be extremely helpful! I'm rendering my dialogs in a Shadow DOM for style isolation and getting these exact console errors since the components can't find elements across Shadow DOM boundaries.

@aleksolutions
Copy link

Hi! 👋

Thank you so much for working on this PR!

I encountered this exact issue while developing a browser extension where rendering AlertDialogContent inside a Shadow DOM (using Portal container={shadowRoot}) is necessary for style isolation. This setup causes the TitleWarning check (document.getElementById) to fail, resulting in a false positive console.error because the check doesn't search within the specified container.

This PR seems to address the problem perfectly by making the accessibility check container-aware.

I've tested the changes locally by applying this PR's code using pnpm patch, and I can confirm that it successfully resolves the console error in my Shadow DOM scenario without any apparent side effects. The dialog remains accessible and functional.

This fix is a great improvement for developers working with Radix primitives in environments like browser extensions or micro-frontends that rely on Shadow DOM.

Looking forward to seeing this merged! Thanks again!

@spencermarx
Copy link

spencermarx commented May 4, 2025

Nice work on the MR, would love to see this merge in so we can upgrade and no longer see these console.errors 🙏

@nicogave
Copy link

Also having the issue when integrating the Dialog in Shadow Dom, can't wait for this fix to be merged !

Cheers !

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.

@radix-ui/react-dialog: Accessibility error inside shadow dom
6 participants