Skip to content

Commit

Permalink
[fixed] appElement detection...
Browse files Browse the repository at this point in the history
We can't use window.HTMLElement to check the `appElement`
when combined in a iframe.

window.HTMLElement !== window.HTMLElement (on the iframe)
  • Loading branch information
diasbruno committed May 14, 2021
1 parent 9523683 commit a29494f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/components/Modal.js
Expand Up @@ -57,7 +57,7 @@ class Modal extends Component {
})
]),
appElement: PropTypes.oneOfType([
PropTypes.instanceOf(SafeHTMLElement),
SafeHTMLElement,
PropTypes.instanceOf(SafeHTMLCollection),
PropTypes.instanceOf(SafeNodeList),
PropTypes.arrayOf(PropTypes.instanceOf(SafeHTMLElement))
Expand Down
2 changes: 1 addition & 1 deletion src/components/ModalPortal.js
Expand Up @@ -47,7 +47,7 @@ export default class ModalPortal extends Component {
htmlOpenClassName: PropTypes.string,
ariaHideApp: PropTypes.bool,
appElement: PropTypes.oneOfType([
PropTypes.instanceOf(SafeHTMLElement),
SafeHTMLElement,
PropTypes.instanceOf(SafeHTMLCollection),
PropTypes.instanceOf(SafeNodeList),
PropTypes.arrayOf(PropTypes.instanceOf(SafeHTMLElement))
Expand Down
18 changes: 17 additions & 1 deletion src/helpers/safeHTMLElement.js
Expand Up @@ -2,7 +2,23 @@ import ExecutionEnvironment from "exenv";

const EE = ExecutionEnvironment;

const SafeHTMLElement = EE.canUseDOM ? window.HTMLElement : {};
const NodeTypeElement = 1;

const IHTMLElement = function(props, propName) {
const element = props[propName];

if (!element || element.nodeType !== NodeTypeElement) return;

const isValid = Boolean(element.setAttribute && element.removeAttribute);

if (!isValid) {
return new Error(
`Warning: Invalid prop \`${propName}\` supplied to \`Modal\``
);
}
};

export const SafeHTMLElement = EE.canUseDOM ? IHTMLElement : {};

export const SafeHTMLCollection = EE.canUseDOM ? window.HTMLCollection : {};

Expand Down

0 comments on commit a29494f

Please sign in to comment.