fix(data-table): prevent component cell clipping

- apply table-level truncation only to primitive text cells.
- let tables expand to content width with horizontal scrolling to avoid column overlap.
- update model badges to show full model names on one line.
This commit is contained in:
QuentinHsu
2026-06-16 17:23:25 +08:00
parent eb86311604
commit 34287afec7
3 changed files with 33 additions and 25 deletions
+25 -21
View File
@@ -57,17 +57,22 @@ function DataTableRowInner<TData>({
className={className}
{...rowProps}
>
{row.getVisibleCells().map((cell) => (
<TableCell
key={cell.id}
className={cn(
'max-w-full min-w-0 overflow-hidden',
getColumnClassName?.(cell.column.id, 'cell')
)}
>
{renderCellContent(cell)}
</TableCell>
))}
{row.getVisibleCells().map((cell) => {
const renderedCell = renderCellContent(cell)
return (
<TableCell
key={cell.id}
className={cn(
'max-w-full min-w-0',
renderedCell.isPrimitive && 'overflow-hidden',
getColumnClassName?.(cell.column.id, 'cell')
)}
>
{renderedCell.content}
</TableCell>
)
})}
</TableRow>
)
}
@@ -100,9 +105,16 @@ function renderCellContent<TData>(cell: Cell<TData, unknown>) {
const content = flexRender(cell.column.columnDef.cell, cell.getContext())
const textContent = getPrimitiveTextContent(content)
if (!textContent) return content
if (!textContent) {
return { content, isPrimitive: false }
}
return <TruncatedCell tooltipContent={textContent}>{content}</TruncatedCell>
return {
content: (
<TruncatedCell tooltipContent={textContent}>{content}</TruncatedCell>
),
isPrimitive: true,
}
}
function getPrimitiveTextContent(content: React.ReactNode): string | null {
@@ -110,13 +122,5 @@ function getPrimitiveTextContent(content: React.ReactNode): string | null {
return String(content)
}
if (
React.isValidElement<{ children?: React.ReactNode }>(content) &&
(typeof content.props.children === 'string' ||
typeof content.props.children === 'number')
) {
return String(content.props.children)
}
return null
}
+5 -1
View File
@@ -26,5 +26,9 @@ export function getTableSizeStyle<TData>(
.getVisibleLeafColumns()
.reduce((total, column) => total + column.getSize(), 0)
return { minWidth: width, tableLayout: 'fixed', width: '100%' }
return {
minWidth: `max(100%, ${width}px)`,
tableLayout: 'auto',
width: 'max-content',
}
}