Skip to content

Commit bd5d870

Browse files
committed
fix(table): address resize review follow-ups
1 parent 099ffd8 commit bd5d870

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed

assets/demo.gif

-10.8 MB
Binary file not shown.

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.24",
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 & 5 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,7 +773,7 @@ export function DataTable<T extends Record<string, unknown>>({
753773
)}
754774
</th>
755775
))}
756-
{tableConfig.enableColumnResizing && <th aria-hidden="true" />}
776+
{renderResizePlaceholderCell("th")}
757777
</tr>
758778
))}
759779
</thead>
@@ -781,7 +801,7 @@ export function DataTable<T extends Record<string, unknown>>({
781801
<div className="h-6 w-full animate-pulse rounded bg-muted" />
782802
</td>
783803
))}
784-
{tableConfig.enableColumnResizing && <td aria-hidden="true" />}
804+
{renderResizePlaceholderCell("td")}
785805
</tr>
786806
))
787807
) : table.getRowModel().rows?.length ? (
@@ -827,11 +847,14 @@ export function DataTable<T extends Record<string, unknown>>({
827847
)}
828848
</td>
829849
))}
830-
{tableConfig.enableColumnResizing && <td aria-hidden="true" />}
850+
{renderResizePlaceholderCell("td")}
831851
</tr>
832852
{row.getIsExpanded() && renderSubRow && (
833853
<tr key={`expanded-${row.id}`} className="bg-muted/30 hover:bg-muted/30 border-b">
834-
<td colSpan={row.getVisibleCells().length + (tableConfig.enableColumnResizing ? 1 : 0)} className="p-0">
854+
<td
855+
colSpan={getVisibleColumnCount(row.getVisibleCells().length)}
856+
className="p-0"
857+
>
835858
{renderSubRow({ row: row.original, table: tableContextRef.current })}
836859
</td>
837860
</tr>
@@ -842,7 +865,7 @@ export function DataTable<T extends Record<string, unknown>>({
842865
<tr data-slot="table-row">
843866
<td
844867
data-slot="table-cell"
845-
colSpan={resolvedColumns.length + (tableConfig.enableColumnResizing ? 1 : 0)}
868+
colSpan={totalVisibleColumns}
846869
className="h-24 text-center text-muted-foreground"
847870
>
848871
No results.

packages/table/src/styles.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ 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;
119123
width: max-content;

0 commit comments

Comments
 (0)