From 283899a07b200141e31cffe62d59354825c09b6f Mon Sep 17 00:00:00 2001 From: Uyarn Date: Mon, 2 Dec 2024 21:14:55 +0800 Subject: [PATCH] fix(Tree): fix tree scroll to top when resize --- src/hooks/useVirtualScrollNew.ts | 2 ++ src/tree/hooks/useTreeScroll.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/hooks/useVirtualScrollNew.ts b/src/hooks/useVirtualScrollNew.ts index 4ca901f219..ead790ee77 100644 --- a/src/hooks/useVirtualScrollNew.ts +++ b/src/hooks/useVirtualScrollNew.ts @@ -20,6 +20,7 @@ export type UseVirtualScrollParams = Ref<{ /** 固定行(冻结行),示例:[M, N],表示冻结头 M 行和尾 N 行。M 和 N 值为 0 时,表示不冻结行 */ fixedRows?: Array; }; + preventResizeRefresh?: boolean; }>; export interface ScrollToElementParams { @@ -170,6 +171,7 @@ const useVirtualScroll = (container: Ref, params: UseVirtual const refreshVirtualScroll = ([{ contentRect }]: [ResizeObserverEntry]) => { // 如果宽度发生变化,重置滚动位置 + if (params.value.preventResizeRefresh) return; const maxScrollbarWidth = 16; if (Math.abs(contentRect.width - containerWidth.value) > maxScrollbarWidth && !!container.value) { container.value.scrollTop = 0; diff --git a/src/tree/hooks/useTreeScroll.ts b/src/tree/hooks/useTreeScroll.ts index e2e57509f5..7d0efdf9df 100644 --- a/src/tree/hooks/useTreeScroll.ts +++ b/src/tree/hooks/useTreeScroll.ts @@ -23,6 +23,7 @@ export default function useTreeScroll(state: TypeTreeState) { return { data: list, scroll: scrollProps.value, + preventResizeRefresh: true, }; }); @@ -63,6 +64,7 @@ export default function useTreeScroll(state: TypeTreeState) { const isVirtual = virtualConfig?.isVirtualScroll.value; const target = (e.target || e.srcElement) as HTMLElement; const top = target.scrollTop; + // 排除横向滚动触发的纵向虚拟滚动计算 if (lastScrollY !== top) { if (isVirtual) {