fix: improve the dialog and drawer scrollbar experience, fix internal click failure problems and warnings (#4391)
* fix: improve the dialog and drawer scrollbar experience, fix internal click failure problems and warnings * chore: remove test code
This commit is contained in:
@@ -2,6 +2,7 @@ export * from './use-content-style';
|
||||
export * from './use-is-mobile';
|
||||
export * from './use-namespace';
|
||||
export * from './use-priority-value';
|
||||
export * from './use-scroll-lock';
|
||||
export * from './use-simple-locale';
|
||||
export * from './use-sortable';
|
||||
export {
|
||||
|
48
packages/@core/composables/src/use-scroll-lock.ts
Normal file
48
packages/@core/composables/src/use-scroll-lock.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { getScrollbarWidth } from '@vben-core/shared/utils';
|
||||
|
||||
import {
|
||||
useScrollLock as _useScrollLock,
|
||||
tryOnBeforeMount,
|
||||
tryOnBeforeUnmount,
|
||||
} from '@vueuse/core';
|
||||
|
||||
export const SCROLL_FIXED_CLASS = `_scroll__fixed_`;
|
||||
|
||||
export function useScrollLock() {
|
||||
const isLocked = _useScrollLock(document.body);
|
||||
const scrollbarWidth = getScrollbarWidth();
|
||||
|
||||
tryOnBeforeMount(() => {
|
||||
document.body.style.paddingRight = `${scrollbarWidth}px`;
|
||||
|
||||
const layoutFixedNodes = document.querySelectorAll<HTMLElement>(
|
||||
`.${SCROLL_FIXED_CLASS}`,
|
||||
);
|
||||
const nodes = [...layoutFixedNodes];
|
||||
if (nodes.length > 0) {
|
||||
nodes.forEach((node) => {
|
||||
node.dataset.transition = node.style.transition;
|
||||
node.style.transition = 'none';
|
||||
node.style.paddingRight = `${scrollbarWidth}px`;
|
||||
});
|
||||
}
|
||||
isLocked.value = true;
|
||||
});
|
||||
|
||||
tryOnBeforeUnmount(() => {
|
||||
isLocked.value = false;
|
||||
const layoutFixedNodes = document.querySelectorAll<HTMLElement>(
|
||||
`.${SCROLL_FIXED_CLASS}`,
|
||||
);
|
||||
const nodes = [...layoutFixedNodes];
|
||||
if (nodes.length > 0) {
|
||||
nodes.forEach((node) => {
|
||||
node.style.paddingRight = '';
|
||||
requestAnimationFrame(() => {
|
||||
node.style.transition = node.dataset.transition || '';
|
||||
});
|
||||
});
|
||||
}
|
||||
document.body.style.paddingRight = '';
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user