Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[dialog] Fix backdrop clicks inside shadow roots and iframes#2871

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
atomiks wants to merge1 commit intomui:master
base:master
Choose a base branch
Loading
fromatomiks:fix/dialog-shadow-root-iframe-outside

Conversation

atomiks
Copy link
Contributor

@atomiksatomiks commentedOct 1, 2025
edited
Loading

Fixes#2867

This solution doesn't seem to work in CodeSandbox iframe.

I can't reproduce the issue locally with a localiframe inbeta.3 to begin with though:

import*asReactfrom"react";import*asReactDOMfrom"react-dom/client";import{createPortal}from"react-dom";import{Dialog}from"@base-ui-components/react/dialog";/** * Dialog rendered entirely inside an iframe (similar to CodeSandbox behavior). * The whole React subtree (trigger + popup) is portaled into the iframe's body. */exportfunctionExampleDialog({  portalContainer,}:{portalContainer:HTMLElement|ShadowRoot;// generalized beyond ShadowRoot}){return(<Dialog.Root><Dialog.Trigger>Open Dialog</Dialog.Trigger><Dialog.Portalcontainer={portalContainer}><Dialog.Backdropstyle={{position:"fixed",inset:0,background:"#00000022"}}/><Dialog.Popupstyle={{position:"fixed",top:"30%",border:"1px solid",background:"white",padding:10,}}><Dialog.Title>Title</Dialog.Title><Dialog.Description>Dialog Description</Dialog.Description><Dialog.Close>Close</Dialog.Close></Dialog.Popup></Dialog.Portal></Dialog.Root>);}/** * Hosts the React dialog UI inside an iframe for isolation. */functionIFrameHost(){const[iframeEl,setIframeEl]=React.useState<HTMLIFrameElement|null>(null);constmountNode=iframeEl?.contentWindow?.document.body??null;constensureDefinition=React.useCallback((doc:Document)=>{constwin=doc.defaultView;if(!win)return;if(win.customElements.get("webcomponent-example"))return;constOuterReactDOM=ReactDOM;classWebcomponentExampleextendswin.HTMLElement{private_shadow:ShadowRoot;private_mountEl?:HTMLDivElement;private_reactRoot?:ReturnType<typeofOuterReactDOM.createRoot>;constructor(){super();this._shadow=this.attachShadow({mode:"open"});}connectedCallback(){if(this._reactRoot)return;this._mountEl=(this.ownerDocument||doc).createElement("div");this._shadow.appendChild(this._mountEl);this._reactRoot=OuterReactDOM.createRoot(this._mountEl);this._reactRoot.render(<ExampleDialogportalContainer={this._shadow}/>);}disconnectedCallback(){if(this._reactRoot){this._reactRoot.unmount();this._reactRoot=undefined;}if(this._mountEl&&this._mountEl.parentNode){this._mountEl.parentNode.removeChild(this._mountEl);this._mountEl=undefined;}}}win.customElements.define("webcomponent-example",WebcomponentExample);},[]);React.useLayoutEffect(()=>{if(mountNode){mountNode.style.margin="0";ensureDefinition(mountNode.ownerDocument);}},[mountNode,ensureDefinition]);return(<iframeref={setIframeEl}// about:blank same-origin content; no srcDoc so load event is implicitwidth={"100%"}height={400}style={{border:"1px solid #ccc"}}title="Dialog IFrame Sandbox">{mountNode&&createPortal(// Render custom element after it's defined in that documentReact.createElement("webcomponent-example"),mountNode)}</iframe>);}exportdefaultfunctionExample(){return<IFrameHost/>;}

@atomiksatomiks added type: bugIt doesn't behave as expected. scope: dialogChanges related to the dialog. labelsOct 1, 2025
@pkg-pr-newpkg.pr.new
Copy link

vite-css-base-ui-example

pnpm add https://pkg.pr.new/mui/base-ui/@base-ui-components/react@2871
pnpm add https://pkg.pr.new/mui/base-ui/@base-ui-components/utils@2871

commit:46e1dcc

@netlifyNetlify
Copy link

netlifybot commentedOct 1, 2025

Deploy Preview forbase-ui ready!

NameLink
🔨 Latest commit46e1dcc
🔍 Latest deploy loghttps://app.netlify.com/projects/base-ui/deploys/68dca707bbf6550008b190f6
😎 Deploy Previewhttps://deploy-preview-2871--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to yourNetlify project configuration.

@mui-bot
Copy link

mui-bot commentedOct 1, 2025
edited
Loading

Bundle size report

BundleParsed sizeGzip size
@base-ui-components/react🔺+2B(0.00%)🔺+9B(+0.01%)

Details of bundle changes

@github-actionsgithub-actionsbot added the PR: out-of-dateThe pull request has merge conflicts and can't be merged. labelOct 1, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@colmtuitecolmtuiteAwaiting requested review from colmtuitecolmtuite will be requested when the pull request is marked ready for reviewcolmtuite is a code owner

@michaldudakmichaldudakAwaiting requested review from michaldudakmichaldudak will be requested when the pull request is marked ready for reviewmichaldudak is a code owner

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Labels
PR: out-of-dateThe pull request has merge conflicts and can't be merged.scope: dialogChanges related to the dialog.type: bugIt doesn't behave as expected.
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

[dialog] Click events on backdrop not dismissing popup when portal container is ShadowRoot
2 participants
@atomiks@mui-bot

[8]ページ先頭

©2009-2025 Movatter.jp