fix(grid): prevent horizontal scrollbar row overlap
This commit is contained in:
1 parent
ee3de0525e
commit
b509520382
3 files changed
+74
-4
No files matched your search
@@ -0,0 +1,32 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { dataGridBottomScrollTop, isDataGridAtScrollBottom } from "@/lib/dataGrid/dataGridInfiniteScroll";
|
||||
|
||||
describe("data grid bottom anchoring", () => {
|
||||
it("keeps DOM rows anchored when scrollbar padding increases the scroll height", () => {
|
||||
const before = { scrollTop: 740, scrollHeight: 1000, clientHeight: 260 };
|
||||
const after = { scrollHeight: 1010, clientHeight: 260 };
|
||||
|
||||
expect(isDataGridAtScrollBottom(before)).toBe(true);
|
||||
expect(dataGridBottomScrollTop(after)).toBe(750);
|
||||
});
|
||||
|
||||
it("keeps canvas rows anchored when scrollbar margin reduces the viewport", () => {
|
||||
const before = { scrollTop: 740, scrollHeight: 1000, clientHeight: 260 };
|
||||
const after = { scrollHeight: 1000, clientHeight: 250 };
|
||||
|
||||
expect(isDataGridAtScrollBottom(before)).toBe(true);
|
||||
expect(dataGridBottomScrollTop(after)).toBe(750);
|
||||
});
|
||||
|
||||
it("keeps the quick-entry draft row visible after the horizontal scrollbar appears", () => {
|
||||
const before = { scrollTop: 766, scrollHeight: 1026, clientHeight: 260 };
|
||||
const after = { scrollHeight: 1036, clientHeight: 260 };
|
||||
|
||||
expect(isDataGridAtScrollBottom(before)).toBe(true);
|
||||
expect(dataGridBottomScrollTop(after)).toBe(776);
|
||||
});
|
||||
|
||||
it("does not anchor a user who is away from the bottom", () => {
|
||||
expect(isDataGridAtScrollBottom({ scrollTop: 700, scrollHeight: 1000, clientHeight: 260 })).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -25,3 +25,12 @@ export function shouldCheckInfiniteScrollAfterScroll(previous: DataGridScrollPos
|
||||
export function isDataGridNearScrollBottom(metrics: DataGridScrollMetrics, threshold = 100): boolean {
|
||||
return metrics.scrollHeight - metrics.scrollTop - metrics.clientHeight < threshold;
|
||||
}
|
||||
|
||||
export function isDataGridAtScrollBottom(metrics: DataGridScrollMetrics, tolerance = 1): boolean {
|
||||
const maxScrollTop = Math.max(0, metrics.scrollHeight - metrics.clientHeight);
|
||||
return maxScrollTop - metrics.scrollTop <= tolerance;
|
||||
}
|
||||
|
||||
export function dataGridBottomScrollTop(metrics: Pick<DataGridScrollMetrics, "scrollHeight" | "clientHeight">): number {
|
||||
return Math.max(0, metrics.scrollHeight - metrics.clientHeight);
|
||||
}
|
||||
Reference in new issue
Block a user