Skip to content

Commit

Permalink
Merge pull request #1350 from Wizleap-Inc/fix/unmount-scrolllock-dialog
Browse files Browse the repository at this point in the history
Fix/unmount-scrolllock-dialog
  • Loading branch information
ichi-h authored Aug 22, 2024
2 parents fa07623 + 7c8c812 commit db87d06
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/early-files-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wizleap-inc/wiz-ui-next": patch
---

Fix(dialog): unmount 時にスクロール固定のスタイル等を解除する
29 changes: 20 additions & 9 deletions packages/wiz-ui-next/src/components/base/dialog/dialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@

<script setup lang="ts">
import {
THEME,
ComponentName,
ARIA_LABELS,
ComponentName,
THEME,
} from "@wizleap-inc/wiz-ui-constants";
import {
dialogBlockScrollStyle,
dialogMaskStyle,
dialogStyle,
dialogVisibleStyle,
dialogMaskStyle,
dialogBlockScrollStyle,
} from "@wizleap-inc/wiz-ui-styles/bases/dialog.css";
import { computed, PropType, watch } from "vue";
import { computed, onUnmounted, PropType, watch } from "vue";
import { WizIconButton } from "@/components/base/buttons";
import { WizCard } from "@/components/base/card";
Expand Down Expand Up @@ -92,6 +92,14 @@ const { currentZIndex } = useZIndex(THEME.zIndex.dialog);
let scrollY = 0;
// スクロールロックを解除する関数を定義
const cleanupScrollLock = () => {
document.body.classList.remove(dialogBlockScrollStyle);
document.body.style.top = "";
window.scrollTo(0, scrollY);
scrollY = 0;
};
watch(
() => visible.value,
(value) => {
Expand All @@ -103,11 +111,14 @@ watch(
document.body.classList.add(dialogBlockScrollStyle);
}
} else {
document.body.classList.remove(dialogBlockScrollStyle);
document.body.style.top = "";
window.scrollTo(0, scrollY);
scrollY = 0;
cleanupScrollLock();
}
}
);
onUnmounted(() => {
if (visible.value) {
cleanupScrollLock();
}
});
</script>

0 comments on commit db87d06

Please sign in to comment.