Skip to content

Commit

Permalink
fix: ensure initial overflow status is stored when opening multiple m…
Browse files Browse the repository at this point in the history
…odals
  • Loading branch information
fabio-aiello-appfolio committed Oct 27, 2022
1 parent b46a23c commit c0191ec
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 c0191ec

Please sign in to comment.