Skip to content

Commit 0adc3e6

Browse files
authored
Merge pull request #30 from jacksonkasi1/dev
fix(table): prevent column resize layout shift
2 parents 2f26b45 + bd5d870 commit 0adc3e6

File tree

6 files changed

+37
-6
lines changed

6 files changed

+37
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<p align="center">
2-
<img src="./assets/demo.gif" alt="TableCraft - Complex table setup in 5 minutes" width="100%" />
2+
<img src="./assets/demo.png" alt="TableCraft - Complex table setup in 5 minutes" width="100%" />
33
</p>
44

55
# TableCraft

assets/demo.gif

-10.8 MB
Binary file not shown.

assets/demo.png

1 MB
Loading

packages/table/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tablecraft/table",
3-
"version": "0.2.23",
3+
"version": "0.2.25",
44
"description": "Schema-driven data table for React — built on TanStack Table + Shadcn UI with native TableCraft engine support",
55
"type": "module",
66
"main": "dist/index.js",

packages/table/src/data-table.tsx

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,26 @@ export function DataTable<T extends Record<string, unknown>>({
670670
pageSizeOptionsProp ??
671671
tableConfig.pageSizeOptions ?? [10, 20, 30, 40, 50];
672672

673+
const resizePlaceholderColumnCount = tableConfig.enableColumnResizing ? 1 : 0;
674+
675+
const getVisibleColumnCount = (columnCount: number) =>
676+
columnCount + resizePlaceholderColumnCount;
677+
678+
const renderResizePlaceholderCell = (cellTag: "th" | "td") => {
679+
if (!resizePlaceholderColumnCount) {
680+
return null;
681+
}
682+
683+
return React.createElement(cellTag, {
684+
"aria-hidden": true,
685+
role: "presentation",
686+
});
687+
};
688+
689+
const totalVisibleColumns = getVisibleColumnCount(
690+
table.getVisibleLeafColumns().length
691+
);
692+
673693
return (
674694
<div className={cn("space-y-4", className)}>
675695
{tableConfig.enableToolbar && (
@@ -753,6 +773,7 @@ export function DataTable<T extends Record<string, unknown>>({
753773
)}
754774
</th>
755775
))}
776+
{renderResizePlaceholderCell("th")}
756777
</tr>
757778
))}
758779
</thead>
@@ -780,6 +801,7 @@ export function DataTable<T extends Record<string, unknown>>({
780801
<div className="h-6 w-full animate-pulse rounded bg-muted" />
781802
</td>
782803
))}
804+
{renderResizePlaceholderCell("td")}
783805
</tr>
784806
))
785807
) : table.getRowModel().rows?.length ? (
@@ -825,10 +847,14 @@ export function DataTable<T extends Record<string, unknown>>({
825847
)}
826848
</td>
827849
))}
850+
{renderResizePlaceholderCell("td")}
828851
</tr>
829852
{row.getIsExpanded() && renderSubRow && (
830853
<tr key={`expanded-${row.id}`} className="bg-muted/30 hover:bg-muted/30 border-b">
831-
<td colSpan={row.getVisibleCells().length} className="p-0">
854+
<td
855+
colSpan={getVisibleColumnCount(row.getVisibleCells().length)}
856+
className="p-0"
857+
>
832858
{renderSubRow({ row: row.original, table: tableContextRef.current })}
833859
</td>
834860
</tr>
@@ -839,7 +865,7 @@ export function DataTable<T extends Record<string, unknown>>({
839865
<tr data-slot="table-row">
840866
<td
841867
data-slot="table-cell"
842-
colSpan={resolvedColumns.length}
868+
colSpan={totalVisibleColumns}
843869
className="h-24 text-center text-muted-foreground"
844870
>
845871
No results.

packages/table/src/styles.css

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,15 @@ input[type="week"] {
113113
──────────────────────────────────────────────────────────────────────────── */
114114

115115
@layer components {
116-
/* Prevent layout shifts during resize */
116+
/*
117+
* Prevent layout shifts during resize while keeping the table full width by
118+
* default. The overflow-x-auto container intentionally absorbs the extra
119+
* horizontal overflow once resized columns exceed the available space.
120+
*/
117121
.resizable-table {
118122
table-layout: fixed;
119-
width: 100%;
123+
width: max-content;
124+
min-width: 100%;
120125
will-change: contents;
121126
}
122127

0 commit comments

Comments
 (0)