Skip to content

Commit 9bf0d4f

Browse files
leoc4ediasbruno
authored andcommitted
[fixed]: css class added to root document in iframe
1 parent 4030935 commit 9bf0d4f

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

docs/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ import ReactModal from 'react-modal';
9090

9191
bodyOpenClassName={
9292
"ReactModal__Body--open"
93-
/* String className to be applied to the document.body
93+
/* String className to be applied to the modal ownerDocument.body
9494
(must be a constant string).
9595
This attribute when set as `null` doesn't add any class
9696
to document.body.
9797
See the `Styles` section for more details. */}
9898

9999
htmlOpenClassName={
100100
"ReactModal__Html--open"
101-
/* String className to be applied to the document.html
101+
/* String className to be applied to the modal ownerDocument.html
102102
(must be a constant string).
103103
This attribute is `null` by default.
104104
See the `Styles` section for more details. */}

src/components/ModalPortal.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export default class ModalPortal extends Component {
4343
}),
4444
className: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
4545
overlayClassName: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
46+
parentSelector: PropTypes.func,
4647
bodyOpenClassName: PropTypes.string,
4748
htmlOpenClassName: PropTypes.string,
4849
ariaHideApp: PropTypes.bool,
@@ -149,15 +150,19 @@ export default class ModalPortal extends Component {
149150
appElement,
150151
ariaHideApp,
151152
htmlOpenClassName,
152-
bodyOpenClassName
153+
bodyOpenClassName,
154+
parentSelector
153155
} = this.props;
154156

157+
const parentDocument =
158+
(parentSelector && parentSelector().ownerDocument) || document;
159+
155160
// Add classes.
156-
bodyOpenClassName && classList.add(document.body, bodyOpenClassName);
161+
bodyOpenClassName && classList.add(parentDocument.body, bodyOpenClassName);
157162

158163
htmlOpenClassName &&
159164
classList.add(
160-
document.getElementsByTagName("html")[0],
165+
parentDocument.getElementsByTagName("html")[0],
161166
htmlOpenClassName
162167
);
163168

@@ -174,15 +179,20 @@ export default class ModalPortal extends Component {
174179
appElement,
175180
ariaHideApp,
176181
htmlOpenClassName,
177-
bodyOpenClassName
182+
bodyOpenClassName,
183+
parentSelector
178184
} = this.props;
179185

186+
const parentDocument =
187+
(parentSelector && parentSelector().ownerDocument) || document;
188+
180189
// Remove classes.
181-
bodyOpenClassName && classList.remove(document.body, bodyOpenClassName);
190+
bodyOpenClassName &&
191+
classList.remove(parentDocument.body, bodyOpenClassName);
182192

183193
htmlOpenClassName &&
184194
classList.remove(
185-
document.getElementsByTagName("html")[0],
195+
parentDocument.getElementsByTagName("html")[0],
186196
htmlOpenClassName
187197
);
188198

0 commit comments

Comments
 (0)