Skip to content

Commit

Permalink
Fix Firefox case
Browse files Browse the repository at this point in the history
  • Loading branch information
mirka committed Aug 1, 2023
1 parent c0ef731 commit 3ec5c25
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions packages/components/src/popover/test/utils/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,23 @@ const GenericIframe = ( {
children,
...props
}: WordPressComponentProps< { children: React.ReactNode }, 'iframe' > ) => {
const [ iframeRef, setIframeRef ] = useState< HTMLIFrameElement | null >(
null
);
const [ containerNode, setContainerNode ] = useState< HTMLElement >();

return (
<iframe { ...props } title="My Iframe" ref={ setIframeRef }>
{ iframeRef?.contentWindow &&
createPortal(
children,
iframeRef?.contentWindow.document.body
) }
<iframe
{ ...props }
title="My Iframe"
// Waiting for the load event ensures that this works in Firefox.
// See https://github.com/facebook/react/issues/22847#issuecomment-991394558
onLoad={ ( event ) => {
if ( event.currentTarget.contentDocument ) {
setContainerNode(
event.currentTarget.contentDocument.body
);
}
} }
>
{ containerNode && createPortal( children, containerNode ) }
</iframe>
);
};
Expand Down

0 comments on commit 3ec5c25

Please sign in to comment.