Skip to content

Commit 410b8f6

Browse files
authored
fix(popup): remove body styles in onExitDOM (#593)
1 parent de84636 commit 410b8f6

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

packages/main/src/Popup.js

+28-8
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,17 @@ function createBLyBackStyle() {
148148

149149
customBLyBackStyleInserted = true;
150150

151-
const stylesheet = document.styleSheets[0];
152-
stylesheet.insertRule(".sapUiBLyBack {overflow: hidden;position: fixed;width:100%;height: 100%;}", 0);
151+
const bodyStyleSheet = document.createElement("style");
152+
bodyStyleSheet.type = "text/css";
153+
bodyStyleSheet.innerHTML = `
154+
.sapUiBLyBack {
155+
width: 100%;
156+
height: 100%;
157+
position: fixed;
158+
overflow: hidden;
159+
}
160+
`;
161+
document.head.appendChild(bodyStyleSheet);
153162
}
154163

155164
function updateBlockLayers() {
@@ -180,17 +189,24 @@ function updateBodyScrolling(hasModal) {
180189
createBLyBackStyle();
181190

182191
if (hasModal) {
183-
document.body.style.top = `-${window.pageYOffset}px`;
184-
document.body.classList.add("sapUiBLyBack");
192+
addBodyStyles();
185193
} else {
186-
document.body.classList.remove("sapUiBLyBack");
187-
window.scrollTo(0, -parseFloat(document.body.style.top));
188-
document.body.style.top = "";
194+
removeBodyStyles();
189195
}
190-
191196
isBodyScrollingDisabled = hasModal;
192197
}
193198

199+
function addBodyStyles() {
200+
document.body.style.top = `-${window.pageYOffset}px`;
201+
document.body.classList.add("sapUiBLyBack");
202+
}
203+
204+
function removeBodyStyles() {
205+
document.body.classList.remove("sapUiBLyBack");
206+
window.scrollTo(0, -parseFloat(document.body.style.top));
207+
document.body.style.top = "";
208+
}
209+
194210
/**
195211
* @class
196212
* <h3 class="comment-api-title">Overview</h3>
@@ -422,6 +438,10 @@ class Popup extends UI5Element {
422438

423439
this._lastFocusableElement = null;
424440
}
441+
442+
onExitDOM() {
443+
removeBodyStyles();
444+
}
425445
}
426446

427447
export default Popup;

packages/playground/webapp/www/home/core.css

-4
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@
7373
outline: 0 none
7474
}
7575

76-
.sapUiBLyBack {
77-
overflow: hidden
78-
}
79-
8076
.sapUiPopupShield {
8177
position: absolute
8278
}

0 commit comments

Comments
 (0)