Skip to content

Commit da997c4

Browse files
authored
Merge pull request #2639 from fabio-aiello-appfolio/restore-scrolling-when-multiple-modals-close
fix: ensure initial overflow status is stored when opening multiple modals
2 parents b46a23c + c0191ec commit da997c4

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/Modal.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ class Modal extends React.Component {
116116

117117
this._element = null;
118118
this._originalBodyPadding = null;
119-
this._originalBodyOverflow = null;
120119
this.getFocusableChildren = this.getFocusableChildren.bind(this);
121120
this.handleBackdropClick = this.handleBackdropClick.bind(this);
122121
this.handleBackdropMouseDown = this.handleBackdropMouseDown.bind(this);
@@ -371,9 +370,11 @@ class Modal extends React.Component {
371370
}
372371

373372
this._originalBodyPadding = getOriginalBodyPadding();
374-
this._originalBodyOverflow = window.getComputedStyle(
375-
document.body,
376-
).overflow;
373+
if (Modal.openCount < 1) {
374+
Modal.originalBodyOverflow = window.getComputedStyle(
375+
document.body,
376+
).overflow;
377+
};
377378
conditionallyUpdateScrollbar();
378379

379380
if (Modal.openCount === 0) {
@@ -419,7 +420,7 @@ class Modal extends React.Component {
419420
document.body.className = document.body.className
420421
.replace(modalOpenClassNameRegex, ' ')
421422
.trim();
422-
document.body.style.overflow = this._originalBodyOverflow;
423+
document.body.style.overflow = Modal.originalBodyOverflow;
423424
}
424425
this.manageFocusAfterClose();
425426
Modal.openCount = Math.max(0, Modal.openCount - 1);
@@ -571,5 +572,6 @@ class Modal extends React.Component {
571572
Modal.propTypes = propTypes;
572573
Modal.defaultProps = defaultProps;
573574
Modal.openCount = 0;
575+
Modal.originalBodyOverflow = null;
574576

575577
export default Modal;

0 commit comments

Comments
 (0)