Skip to content

feat(overlay): make dialogs work inside a shadow root - #29

Merged
antfu merged 1 commit into
mainfrom
feat/dialog-shadow-root
Sep 21, 2026
Merged

antfu merged 1 commit into
mainfrom
feat/dialog-shadow-root

Conversation

@antfubot

Copy link
Copy Markdown
Collaborator

What

OverlayModal, OverlayDrawer, and OverlayConfirm teleport their content to document.body by default (via reka-ui's portal). Inside a shadow root — a web component mounted with defineCustomElement, 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 ConfigProvider teleport-to dance 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 usePortalTarget composable detects the enclosing ShadowRoot from an anchor in the component's own tree and teleports the portal into it; outside a shadow root it returns undefined, so reka's own ConfigProvider/body resolution is unchanged. Each dialog also gains an optional to prop 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 explicit to.

This PR was created with the help of an agent.

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.
@antfu
antfu merged commit 94b9a05 into main Sep 21, 2026
5 checks passed
@antfu
antfu deleted the feat/dialog-shadow-root branch September 21, 2026 06:18
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.

2 participants