Skip to content
This repository was archived by the owner on Jan 10, 2025. It is now read-only.

Commit 15f9ea6

Browse files
committed
S-54545 pull in a fix for setting the element of the modal.
see react-modal >> [fixed] Restore Modal.setAppElement() functionality reactjs#108
1 parent 5399d9a commit 15f9ea6

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/components/Modal.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ var ariaAppHider = require('../helpers/ariaAppHider');
55
var injectCSS = require('../helpers/injectCSS');
66

77
var SafeHTMLElement = ExecutionEnvironment.canUseDOM ? window.HTMLElement : {};
8+
var AppElement = ExecutionEnvironment.canUseDOM ? document.body : {appendChild: function() {}};
89

910
var Modal = module.exports = React.createClass({
1011

1112
displayName: 'Modal',
1213

1314
statics: {
14-
setAppElement: ariaAppHider.setElement,
15+
setAppElement: function(element) {
16+
AppElement = ariaAppHider.setElement(element);
17+
},
1518
injectCSS: injectCSS
1619
},
1720

@@ -46,7 +49,7 @@ var Modal = module.exports = React.createClass({
4649
componentDidMount: function() {
4750
this.node = document.createElement('div');
4851
this.node.className = 'ReactModalPortal';
49-
document.body.appendChild(this.node);
52+
AppElement.appendChild(this.node);
5053
this.renderPortal(this.props);
5154
},
5255

@@ -56,7 +59,7 @@ var Modal = module.exports = React.createClass({
5659

5760
componentWillUnmount: function() {
5861
React.unmountComponentAtNode(this.node);
59-
document.body.removeChild(this.node);
62+
AppElement.removeChild(this.node);
6063
},
6164

6265
renderPortal: function(props) {

lib/helpers/ariaAppHider.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
var _element = null;
22

33
function setElement(element) {
4-
_element = element;
4+
if (typeof element === 'string') {
5+
var el = document.querySelectorAll(element);
6+
element = 'length' in el ? el[0] : el;
7+
}
8+
_element = element || _element;
9+
return _element;
510
}
611

712
function hide(appElement) {

0 commit comments

Comments
 (0)