Skip to content

Commit 6d8c31b

Browse files
Fix Safari grid horizontal scrolling (#1512)
1 parent 1a3731f commit 6d8c31b

2 files changed

Lines changed: 57 additions & 2 deletions

File tree

ui/components/ui/table.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const Table = React.forwardRef<HTMLTableElement, TableProps>(
1515
return (
1616
<div
1717
className={cn(
18-
"relative w-full overflow-auto flex items-start h-full",
18+
"relative h-full w-full min-w-0 overflow-auto",
1919
containerClassName,
2020
)}
2121
{...resolvedContainerProps}

ui/studio/grid/DataGrid.layout.test.tsx

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {
44
} from "@tanstack/react-table";
55
import { act, useState } from "react";
66
import { createRoot } from "react-dom/client";
7-
import { afterEach, describe, expect, it, vi } from "vitest";
7+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
88

99
import { DataGrid } from "./DataGrid";
1010
import { createReadOnlyColumns, type GridRow } from "./test-utils";
@@ -13,11 +13,48 @@ import { createReadOnlyColumns, type GridRow } from "./test-utils";
1313
globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }
1414
).IS_REACT_ACT_ENVIRONMENT = true;
1515

16+
beforeEach(() => {
17+
const localStorage = createLocalStorageMock();
18+
Object.defineProperty(globalThis, "localStorage", {
19+
configurable: true,
20+
value: localStorage,
21+
});
22+
Object.defineProperty(window, "localStorage", {
23+
configurable: true,
24+
value: localStorage,
25+
});
26+
});
27+
1628
afterEach(() => {
1729
vi.restoreAllMocks();
1830
document.body.innerHTML = "";
1931
});
2032

33+
function createLocalStorageMock(): Storage {
34+
const entries = new Map<string, string>();
35+
36+
return {
37+
get length() {
38+
return entries.size;
39+
},
40+
clear() {
41+
entries.clear();
42+
},
43+
getItem(key: string) {
44+
return entries.get(key) ?? null;
45+
},
46+
key(index: number) {
47+
return Array.from(entries.keys())[index] ?? null;
48+
},
49+
removeItem(key: string) {
50+
entries.delete(key);
51+
},
52+
setItem(key: string, value: string) {
53+
entries.set(key, value);
54+
},
55+
};
56+
}
57+
2158
function renderGrid(rows: GridRow[]) {
2259
const container = document.createElement("div");
2360
document.body.appendChild(container);
@@ -86,4 +123,22 @@ describe("DataGrid layout", () => {
86123

87124
cleanup();
88125
});
126+
127+
it("keeps the table wrapper as a plain overflow scroller for wide-grid horizontal scrolling", () => {
128+
const { cleanup, table } = renderGrid([
129+
{
130+
__ps_rowid: "row_1",
131+
long_text: "wide",
132+
short_text: "Acme Labs",
133+
},
134+
]);
135+
const scrollContainer = table.parentElement;
136+
137+
expect(scrollContainer).toBeInstanceOf(HTMLDivElement);
138+
expect(scrollContainer?.className).toContain("overflow-auto");
139+
expect(scrollContainer?.className).toContain("min-w-0");
140+
expect(scrollContainer?.className).not.toContain("flex");
141+
142+
cleanup();
143+
});
89144
});

0 commit comments

Comments
 (0)