Skip to content

Commit

Permalink
Merge pull request #2639 from fabio-aiello-appfolio/restore-scrolling…
Browse files Browse the repository at this point in the history
…-when-multiple-modals-close

fix: ensure initial overflow status is stored when opening multiple modals
  • Loading branch information
davidacevedo committed Oct 27, 2022
2 parents b46a23c + c0191ec commit da997c4
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ class Modal extends React.Component {

this._element = null;
this._originalBodyPadding = null;
this._originalBodyOverflow = null;
this.getFocusableChildren = this.getFocusableChildren.bind(this);
this.handleBackdropClick = this.handleBackdropClick.bind(this);
this.handleBackdropMouseDown = this.handleBackdropMouseDown.bind(this);
Expand Down Expand Up @@ -371,9 +370,11 @@ class Modal extends React.Component {
}

this._originalBodyPadding = getOriginalBodyPadding();
this._originalBodyOverflow = window.getComputedStyle(
document.body,
).overflow;
if (Modal.openCount < 1) {
Modal.originalBodyOverflow = window.getComputedStyle(
document.body,
).overflow;
};
conditionallyUpdateScrollbar();

if (Modal.openCount === 0) {
Expand Down Expand Up @@ -419,7 +420,7 @@ class Modal extends React.Component {
document.body.className = document.body.className
.replace(modalOpenClassNameRegex, ' ')
.trim();
document.body.style.overflow = this._originalBodyOverflow;
document.body.style.overflow = Modal.originalBodyOverflow;
}
this.manageFocusAfterClose();
Modal.openCount = Math.max(0, Modal.openCount - 1);
Expand Down Expand Up @@ -571,5 +572,6 @@ class Modal extends React.Component {
Modal.propTypes = propTypes;
Modal.defaultProps = defaultProps;
Modal.openCount = 0;
Modal.originalBodyOverflow = null;

export default Modal;

0 comments on commit da997c4

Please sign in to comment.