Repository navigation
feat(overlay): make dialogs work inside a shadow root - #29
Merged
Merged
Conversation
Dialog-based overlays teleport to document.body by default, which escapes the shadow root that holds the injected stylesheet — so under defineCustomElement the modal/drawer/confirm rendered unstyled and outside their tree. Detect the enclosing ShadowRoot and teleport into it, with a `to` prop to override.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
OverlayModal,OverlayDrawer, andOverlayConfirmteleport their content todocument.bodyby default (via reka-ui's portal). Inside a shadow root — a web component mounted withdefineCustomElement, a devtools dock, an injected overlay — that lands the dialog outside the shadow root that holds the injected stylesheet, so it renders unstyled and detached from its tree.Why
Today the only fix is the
ConfigProviderteleport-todance documented for the dropdown/select family. Dialogs are the most common thing to reach for inside a custom element, and they should just work there.How
A small
usePortalTargetcomposable detects the enclosingShadowRootfrom an anchor in the component's own tree and teleports the portal into it; outside a shadow root it returnsundefined, so reka's ownConfigProvider/bodyresolution is unchanged. Each dialog also gains an optionaltoprop to point the portal at an explicit target.Covered by tests asserting each dialog defaults to
body, stays inside a shadow root (and does not leak to the light-DOM body), and honours an explicitto.This PR was created with the help of an agent.