Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Tree): fix tree scroll to top when resize #4826

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading