fix(grid): stabilize header height during horizontal scroll
This commit is contained in:
1 parent
d3947d246c
commit
51b4c79847
5 files changed
+114
-2
No files matched your search
@@ -0,0 +1,36 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { reserveDataGridHeaderLine } from "@/lib/dataGrid/dataGridHeaderLayout";
|
||||
|
||||
describe("reserveDataGridHeaderLine", () => {
|
||||
it("reserves a line only when the setting and full-column content require it", () => {
|
||||
const values = [{ text: "" }, { text: "later column" }];
|
||||
|
||||
expect(reserveDataGridHeaderLine(false, values, (value) => value.text)).toBe(false);
|
||||
expect(reserveDataGridHeaderLine(true, values, (value) => value.text)).toBe(true);
|
||||
expect(reserveDataGridHeaderLine(true, [{ text: "" }, { text: " " }], (value) => value.text)).toBe(false);
|
||||
expect(reserveDataGridHeaderLine(true, [], (value: { text: string }) => value.text)).toBe(false);
|
||||
});
|
||||
|
||||
it("resolves all columns rather than relying on the currently rendered window", () => {
|
||||
const visited: number[] = [];
|
||||
const reserved = reserveDataGridHeaderLine(true, ["", "", "comment"], (value, index) => {
|
||||
visited.push(index);
|
||||
return value;
|
||||
});
|
||||
|
||||
expect(reserved).toBe(true);
|
||||
expect(visited).toEqual([0, 1, 2]);
|
||||
});
|
||||
|
||||
it("does not reserve a comment line for a comment on an unprojected column", () => {
|
||||
const comments = new Map([["internal_id", "Not selected"]]);
|
||||
|
||||
expect(reserveDataGridHeaderLine(true, ["id", "name"], (column) => comments.get(column))).toBe(false);
|
||||
});
|
||||
|
||||
it("reserves a comment line when a projected column has a comment", () => {
|
||||
const comments = new Map([["name", "Display name"]]);
|
||||
|
||||
expect(reserveDataGridHeaderLine(true, ["id", "name"], (column) => comments.get(column))).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,4 @@
|
||||
/** Resolve header height from the full column set so virtual-window changes cannot resize it. */
|
||||
export function reserveDataGridHeaderLine<T>(enabled: boolean, values: readonly T[], resolveText: (value: T, index: number) => string | null | undefined): boolean {
|
||||
return enabled && values.some((value, index) => Boolean(resolveText(value, index)?.trim()));
|
||||
}
|
||||
Reference in new issue
Block a user