fix(grid): restore scroll after transpose

This commit is contained in:
t8y2 committed 2026-07-15 14:32:48 +08:00
1 parent ceadf73e4b
commit e3350e2ec4
3 files changed
+35 -3

No files matched your search

@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { dataGridBottomScrollTop, isDataGridAtScrollBottom } from "@/lib/dataGrid/dataGridInfiniteScroll";
import { dataGridBottomScrollTop, isDataGridAtScrollBottom, restoredDataGridScrollLeft } from "@/lib/dataGrid/dataGridInfiniteScroll";
describe("data grid bottom anchoring", () => {
it("keeps DOM rows anchored when scrollbar padding increases the scroll height", () => {
@@ -30,3 +30,17 @@ describe("data grid bottom anchoring", () => {
expect(isDataGridAtScrollBottom({ scrollTop: 700, scrollHeight: 1000, clientHeight: 260 })).toBe(false);
});
});
describe("data grid horizontal restoration", () => {
it("restores the previous horizontal position after the grid remounts", () => {
expect(restoredDataGridScrollLeft(320, 1200, 600)).toBe(320);
});
it("clamps the previous position when the scrollable width shrinks", () => {
expect(restoredDataGridScrollLeft(720, 1000, 600)).toBe(400);
});
it("resets the position when the rebuilt grid no longer overflows", () => {
expect(restoredDataGridScrollLeft(320, 500, 600)).toBe(0);
});
});
@@ -16,6 +16,10 @@ export function dataGridScrollPosition(top: number, left: number): DataGridScrol
};
}
export function restoredDataGridScrollLeft(scrollLeft: number, scrollWidth: number, clientWidth: number): number {
return Math.max(0, Math.min(Math.max(0, scrollWidth - clientWidth), scrollLeft));
}
export function shouldCheckInfiniteScrollAfterScroll(previous: DataGridScrollPosition | undefined, current: DataGridScrollPosition): boolean {
if (!previous) return false;
// Shift+wheel horizontal scrolling changes scrollLeft only and must not paginate.