Skip to content

Commit

Permalink
fix(Tree): fix tree scroll to top when resize
Browse files Browse the repository at this point in the history
  • Loading branch information
uyarn committed Dec 2, 2024
1 parent 4bf927f commit 283899a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/hooks/useVirtualScrollNew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type UseVirtualScrollParams = Ref<{
/** 固定行(冻结行),示例:[M, N],表示冻结头 M 行和尾 N 行。M 和 N 值为 0 时,表示不冻结行 */
fixedRows?: Array<number>;
};
preventResizeRefresh?: boolean;
}>;

export interface ScrollToElementParams {
Expand Down Expand Up @@ -170,6 +171,7 @@ const useVirtualScroll = (container: Ref<HTMLElement | null>, 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;
Expand Down
2 changes: 2 additions & 0 deletions src/tree/hooks/useTreeScroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default function useTreeScroll(state: TypeTreeState) {
return {
data: list,
scroll: scrollProps.value,
preventResizeRefresh: true,
};
});

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 283899a

Please sign in to comment.