Skip to content

Commit

Permalink
Merge pull request #233 from asenka0301/fix-modal-widget-behavior
Browse files Browse the repository at this point in the history
[#210] fix(widget): fix site and modal overflow behavior
  • Loading branch information
fey committed Dec 29, 2023
2 parents 276479a + 8ecb25f commit b11404d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/widget/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ const generateModalStyles = () => {
display: none;
width: 100%;
height: 100%;
overflow: hidden;
overflow: auto;
outline: 0;
background-color: rgba(0, 0, 0, 0.5);
}
#hexlet-correction-modal_modal-content {
background-color: #fefefe;
margin: 15% auto;
margin: 10rem auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
Expand Down Expand Up @@ -113,6 +113,14 @@ const generateModalStyles = () => {
return modalStyleEl;
};

const handleBodyScroll = (modalIsOpen) => {
if (modalIsOpen) {
document.body.style.overflow = 'hidden';
} else {
document.body.style.overflow = 'auto';
}
};

const generateModal = (state) => {
generateModalStyles();

Expand Down Expand Up @@ -243,6 +251,7 @@ const view = (elements, state) => {
switch (path) {
case 'modalShown':
renderModal(elements, state);
handleBodyScroll(state.modalShown);
break;
default:
break;
Expand Down

0 comments on commit b11404d

Please sign in to comment.