Skip to content

Commit

Permalink
Merge pull request #41 from RobRendell/master
Browse files Browse the repository at this point in the history
Support reverse portals in iframes and other windows.
pimterry authored Apr 11, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents e269286 + 475880d commit 2aa574e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -44,11 +44,15 @@ type AnyPortalNode<C extends Component<any> = Component<any>> = HtmlPortalNode<C


const validateElementType = (domElement: Element, elementType: ANY_ELEMENT_TYPE) => {
const ownerDocument = (domElement.ownerDocument ?? document) as any;
// Cast document to `any` because Typescript doesn't know about the legacy `Document.parentWindow` field, and also
// doesn't believe `Window.HTMLElement`/`Window.SVGElement` can be used in instanceof tests.
const ownerWindow = ownerDocument.defaultView ?? ownerDocument.parentWindow ?? window; // `parentWindow` for IE8 and earlier
if (elementType === ELEMENT_TYPE_HTML) {
return domElement instanceof HTMLElement;
return domElement instanceof ownerWindow.HTMLElement;
}
if (elementType === ELEMENT_TYPE_SVG) {
return domElement instanceof SVGElement;
return domElement instanceof ownerWindow.SVGElement;
}
throw new Error(`Unrecognized element type "${elementType}" for validateElementType.`);
};

0 comments on commit 2aa574e

Please sign in to comment.