Skip to content

Commit bd91ab7

Browse files
authored
fix(files): restore horizontal scroll in CSV and XLSX preview tables (#6550)
* fix(files): restore horizontal scroll in CSV and XLSX preview tables #6125 moved the preview tables onto the markdown table chrome and gave both surfaces `width: 100%`. That is right for prose and wrong for data: a CSV with dozens of columns divides the frame between them, and since the same change added `overflow-wrap: anywhere`, every column was free to break down to a single character — so headers rendered as vertical columns of letters and the table never exceeded its frame, leaving `overflow-x-auto` with nothing to scroll. Split sizing out of the shared rule. Prose tables keep `width: 100%`; preview tables size to their content and scroll, with column bounds so no column collapses to a sliver and one long value wraps instead of pushing the rest off-screen. Chrome (borders, padding, typography, header fill) stays shared. * fix(files): scroll preview tables from one container, not two nested ones DataTable owned `overflow-x-auto` while its caller owns the vertical scroll, so now that preview tables are actually wider than the frame the horizontal scrollbar rendered at the foot of the table rather than at the bottom of the viewport — up to 1,000 rows below it for the two callers whose container is a plain block (xlsx-preview, preview-panel). csv-table-preview escaped it only because its flex column compressed the wrapper to the frame height. Drop the inner overflow so the caller's bounded container scrolls both axes. All three callers now place the scrollbar at the viewport bottom. * fix(files): correct a stale reference to the removed inner overflow The sizing comment still credited `.document-table`'s own `overflow-x-auto` for the horizontal scroll, which the previous commit removed in favour of the caller's container.
1 parent b879960 commit bd91ab7

3 files changed

Lines changed: 55 additions & 4 deletions

File tree

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/data-table.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ type EditingCell = { row: number; col: number } | null
2525
* Tabular renderer for CSV and XLSX previews. Chrome (borders, padding, typography, header fill)
2626
* comes entirely from `document-table.css`, the definition shared with markdown tables in the rich
2727
* markdown editor — the only classes here are the optional edit affordances.
28+
*
29+
* Scrolling belongs to the caller's bounded container, which already scrolls vertically. A preview
30+
* table is wider than its frame, so an `overflow-x` of its own would put the horizontal scrollbar
31+
* at the foot of all {@link CSV_PREVIEW_MAX_ROWS} rows instead of at the bottom of the viewport.
2832
*/
2933
const DataTableBase = forwardRef<DataTableHandle, DataTableProps>(function DataTable(
3034
{ headers, rows, editConfig },
@@ -100,7 +104,7 @@ const DataTableBase = forwardRef<DataTableHandle, DataTableProps>(function DataT
100104
editingCell?.row === row && editingCell?.col === col
101105

102106
return (
103-
<div className='document-table overflow-x-auto'>
107+
<div className='document-table'>
104108
<table>
105109
<thead>
106110
<tr>

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/document-table.css

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
* Canonical table chrome for the file viewer. Both surfaces that render a table for a file — the
33
* rich markdown editor (`.rich-markdown-prose table`) and the tabular previews CSV/XLSX render
44
* through `DataTable` (`.document-table`) — share this one definition so a table looks the same
5-
* whichever file it came from. Editor-only concerns (prose block margin, fixed layout for column
6-
* resizing, cell paragraph reset) stay in rich-markdown-editor.css.
5+
* whichever file it came from. Chrome is shared; *sizing* is not — prose fits the document width
6+
* while a preview sizes to its data and scrolls (see the two rules below). Editor-only concerns
7+
* (prose block margin, fixed layout for column resizing, cell paragraph reset) stay in
8+
* rich-markdown-editor.css.
79
*/
810

911
/* `overflow-wrap` matches what `.rich-markdown-prose` sets on its own root: cells hold arbitrary
@@ -15,11 +17,34 @@
1517

1618
.rich-markdown-prose table,
1719
.document-table table {
18-
width: 100%;
1920
border-collapse: collapse;
2021
overflow: hidden;
2122
}
2223

24+
.rich-markdown-prose table {
25+
width: 100%;
26+
}
27+
28+
/* A preview table is data, not prose. A CSV can carry dozens of columns, so sizing the table to the
29+
frame (`width: 100%`) divides that frame between them and — with `overflow-wrap: anywhere` able to
30+
break every column down to one character — renders each header a vertical column of letters.
31+
`max-content` sizes columns to their values and lets the table exceed the frame, which the
32+
caller's own scroll container then scrolls; `min-width: 100%` keeps a narrow table filling the
33+
frame rather than hugging the left edge. */
34+
.document-table table {
35+
width: max-content;
36+
min-width: 100%;
37+
}
38+
39+
/* Bounds for a content-sized column: no column collapses to a sliver, and one long value (a URL, a
40+
pasted paragraph) wraps at `max-width` instead of pushing every other column off-screen. 80px is
41+
the tables grid's own `COL_WIDTH_MIN`; 320px is the capped content width used across the app. */
42+
.document-table th,
43+
.document-table td {
44+
min-width: 80px;
45+
max-width: 320px;
46+
}
47+
2348
.rich-markdown-prose th,
2449
.rich-markdown-prose td,
2550
.document-table th,

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/document-table.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,28 @@ describe('document-table chrome is shared with markdown tables', () => {
115115
expect(getComputedStyle(preview.root).getPropertyValue('overflow-wrap')).toBe(wrap)
116116
})
117117

118+
it('the preview table sizes to its content while the prose table fits the frame', () => {
119+
const prose = mountTable('rich-markdown-prose')
120+
const preview = mountTable('document-table')
121+
122+
const proseTable = prose.root.querySelector('table')
123+
const previewTable = preview.root.querySelector('table')
124+
if (!proseTable || !previewTable) throw new Error('tables not found')
125+
126+
expect(getComputedStyle(proseTable).getPropertyValue('width')).toBe('100%')
127+
expect(getComputedStyle(previewTable).getPropertyValue('width')).toBe('max-content')
128+
expect(getComputedStyle(previewTable).getPropertyValue('min-width')).toBe('100%')
129+
})
130+
131+
it('a preview column is bounded so no value collapses or monopolises the row', () => {
132+
const { th, td } = mountTable('document-table')
133+
134+
for (const cell of [th, td]) {
135+
expect(getComputedStyle(cell).getPropertyValue('min-width')).toBe('80px')
136+
expect(getComputedStyle(cell).getPropertyValue('max-width')).toBe('320px')
137+
}
138+
})
139+
118140
it('the resolved values are the markdown editor values, not jsdom defaults', () => {
119141
const { th, td } = mountTable('document-table')
120142

0 commit comments

Comments
 (0)