Skip to content

Commit 7517be6

Browse files
committed
[fixed] appElement detection...
We can't use window.HTMLElement to check the `appElement` when combined in a iframe. window.HTMLElement !== window.HTMLElement (on the iframe)
1 parent 76df16b commit 7517be6

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

src/components/Modal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class Modal extends Component {
5959
})
6060
]),
6161
appElement: PropTypes.oneOfType([
62-
PropTypes.instanceOf(SafeHTMLElement),
62+
SafeHTMLElement,
6363
PropTypes.instanceOf(SafeHTMLCollection),
6464
PropTypes.instanceOf(SafeNodeList),
6565
PropTypes.arrayOf(PropTypes.instanceOf(SafeHTMLElement))

src/components/ModalPortal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export default class ModalPortal extends Component {
4747
htmlOpenClassName: PropTypes.string,
4848
ariaHideApp: PropTypes.bool,
4949
appElement: PropTypes.oneOfType([
50-
PropTypes.instanceOf(SafeHTMLElement),
50+
SafeHTMLElement,
5151
PropTypes.instanceOf(SafeHTMLCollection),
5252
PropTypes.instanceOf(SafeNodeList),
5353
PropTypes.arrayOf(PropTypes.instanceOf(SafeHTMLElement))

src/helpers/safeHTMLElement.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,23 @@ import ExecutionEnvironment from "exenv";
22

33
const EE = ExecutionEnvironment;
44

5-
const SafeHTMLElement = EE.canUseDOM ? window.HTMLElement : {};
5+
const NodeTypeElement = 1;
6+
7+
const IHTMLElement = function(props, propName) {
8+
const element = props[propName];
9+
10+
if (!element || element.nodeType !== NodeTypeElement) return;
11+
12+
const isValid = Boolean(element.setAttribute && element.removeAttribute);
13+
14+
if (!isValid) {
15+
return new Error(
16+
`Warning: Invalid prop \`${propName}\` supplied to \`Modal\``
17+
);
18+
}
19+
};
20+
21+
export const SafeHTMLElement = EE.canUseDOM ? IHTMLElement : {};
622

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

0 commit comments

Comments
 (0)