fix: improve the scroll bar flashing when the modal box is opened (#4438)

This commit is contained in:
Vben
2024-09-19 21:56:49 +08:00
committed by GitHub
parent 56bdb8f606
commit 161820dbc1
18 changed files with 530 additions and 42 deletions

View File

@@ -1,4 +1,4 @@
import { getScrollbarWidth } from '@vben-core/shared/utils';
import { getScrollbarWidth, needsScrollbar } from '@vben-core/shared/utils';
import {
useScrollLock as _useScrollLock,
@@ -13,6 +13,9 @@ export function useScrollLock() {
const scrollbarWidth = getScrollbarWidth();
tryOnBeforeMount(() => {
if (!needsScrollbar()) {
return;
}
document.body.style.paddingRight = `${scrollbarWidth}px`;
const layoutFixedNodes = document.querySelectorAll<HTMLElement>(
@@ -30,6 +33,9 @@ export function useScrollLock() {
});
tryOnBeforeUnmount(() => {
if (!needsScrollbar()) {
return;
}
isLocked.value = false;
const layoutFixedNodes = document.querySelectorAll<HTMLElement>(
`.${SCROLL_FIXED_CLASS}`,