Skip to content

Commit badc644

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 9523683 commit badc644

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/components/Modal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class Modal extends Component {
5757
})
5858
]),
5959
appElement: PropTypes.oneOfType([
60-
PropTypes.instanceOf(SafeHTMLElement),
60+
SafeHTMLElement,
6161
PropTypes.instanceOf(SafeHTMLCollection),
6262
PropTypes.instanceOf(SafeNodeList),
6363
PropTypes.arrayOf(PropTypes.instanceOf(SafeHTMLElement))

src/helpers/safeHTMLElement.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,20 @@ 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+
const is = element.nodeType === NodeTypeElement &&
10+
element.setAttribute &&
11+
element.removeAttribute;
12+
13+
if (!is) {
14+
return new Error(`Warning: Failed %s type: %s%s', 'prop', Invalid prop \`${propName}\` supplied to \`Modal\``);
15+
}
16+
};
17+
18+
export const SafeHTMLElement = EE.canUseDOM ? IHTMLElement : {};
619

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

0 commit comments

Comments
 (0)