[#1718] fixed helper overlay-active class not being toggled correctly

This commit is contained in:
Gani Georgiev
2023-01-30 11:56:05 +02:00
parent 6718f4469b
commit 0e1f6b69d0
29 changed files with 128 additions and 114 deletions
+20 -6
View File
@@ -1,6 +1,8 @@
<script context="module">
let holder;
let activePanels = [];
function getHolder() {
holder = holder || document.querySelector(".overlays");
@@ -45,6 +47,7 @@
export let beforeHide = undefined; // function callback called before hide; if return false - no close
const dispatch = createEventDispatcher();
const uniqueId = "op_" + CommonHelper.randomString(10);
let wrapper;
let contentPanel;
@@ -64,6 +67,18 @@
zIndexUpdate();
}
$: if (active) {
// add helper body class
CommonHelper.pushUnique(activePanels, uniqueId);
document.body.classList.add("overlay-active");
} else {
// remove helper body class if there are no other active panels
CommonHelper.removeByValue(activePanels, uniqueId);
if (!activePanels.length) {
document.body.classList.remove("overlay-active");
}
}
export function show() {
if (typeof beforeOpen === "function" && beforeOpen() === false) {
return;
@@ -91,12 +106,7 @@
oldFocusedElem = document.activeElement;
wrapper?.focus();
dispatch("show");
document.body.classList.add("overlay-active");
} else {
if (getHolder().querySelectorAll(".overlay-panel-container.active").length <= 1) {
document.body.classList.remove("overlay-active");
}
clearTimeout(contentScrollThrottle);
oldFocusedElem?.focus();
dispatch("hide");
@@ -190,6 +200,10 @@
// (currently there is a bug with svelte transition)
wrapper?.classList?.add("hidden");
if (!activePanels.length) {
document.body.classList.remove("overlay-active");
}
setTimeout(() => {
wrapper?.remove();
}, 0);
@@ -206,7 +220,7 @@
<div
class="overlay"
on:click|preventDefault={() => (overlayClose ? hide() : true)}
transition:fade={{ duration: transitionSpeed, opacity: 0 }}
transition:fade|local={{ duration: transitionSpeed, opacity: 0 }}
/>
<div