fix(data-table): prevent component cell clipping (#5536)

Merge pull request #5536 from QuantumNous/fix/data-table-component-cells
This commit is contained in:
同語
2026-06-17 21:15:04 +08:00
committed by GitHub
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',
}
}