Skip to content

Commit

Permalink
fix(popup): remove body styles in onExitDOM (#593)
Browse files Browse the repository at this point in the history
  • Loading branch information
fifoosid authored Jun 28, 2019
1 parent de84636 commit 410b8f6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
36 changes: 28 additions & 8 deletions packages/main/src/Popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,17 @@ function createBLyBackStyle() {

customBLyBackStyleInserted = true;

const stylesheet = document.styleSheets[0];
stylesheet.insertRule(".sapUiBLyBack {overflow: hidden;position: fixed;width:100%;height: 100%;}", 0);
const bodyStyleSheet = document.createElement("style");
bodyStyleSheet.type = "text/css";
bodyStyleSheet.innerHTML = `
.sapUiBLyBack {
width: 100%;
height: 100%;
position: fixed;
overflow: hidden;
}
`;
document.head.appendChild(bodyStyleSheet);
}

function updateBlockLayers() {
Expand Down Expand Up @@ -180,17 +189,24 @@ function updateBodyScrolling(hasModal) {
createBLyBackStyle();

if (hasModal) {
document.body.style.top = `-${window.pageYOffset}px`;
document.body.classList.add("sapUiBLyBack");
addBodyStyles();
} else {
document.body.classList.remove("sapUiBLyBack");
window.scrollTo(0, -parseFloat(document.body.style.top));
document.body.style.top = "";
removeBodyStyles();
}

isBodyScrollingDisabled = hasModal;
}

function addBodyStyles() {
document.body.style.top = `-${window.pageYOffset}px`;
document.body.classList.add("sapUiBLyBack");
}

function removeBodyStyles() {
document.body.classList.remove("sapUiBLyBack");
window.scrollTo(0, -parseFloat(document.body.style.top));
document.body.style.top = "";
}

/**
* @class
* <h3 class="comment-api-title">Overview</h3>
Expand Down Expand Up @@ -422,6 +438,10 @@ class Popup extends UI5Element {

this._lastFocusableElement = null;
}

onExitDOM() {
removeBodyStyles();
}
}

export default Popup;
4 changes: 0 additions & 4 deletions packages/playground/webapp/www/home/core.css
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@
outline: 0 none
}

.sapUiBLyBack {
overflow: hidden
}

.sapUiPopupShield {
position: absolute
}
Expand Down

0 comments on commit 410b8f6

Please sign in to comment.