Skip to content

Commit

Permalink
body cell wrapper inner
Browse files Browse the repository at this point in the history
  • Loading branch information
pan-kot committed Nov 28, 2024
1 parent e04b439 commit b2a1194
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
9 changes: 8 additions & 1 deletion pages/table/cell-permutations.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,14 @@ function TableCellsDemo() {
header: `Header cell content ${index}${index === 8 ? ' with longer text' : ''}`,
sortingField: index === 2 ? 'field-1' : index === 3 ? 'field-2' : undefined,
activeSorting: index === 3,
cell: cellContent,
cell: item =>
index === 3 ? (
<StatusIndicator>{cellContent(item)}</StatusIndicator>
) : index === 4 ? (
<Box textAlign="right">{index}</Box>
) : (
cellContent(item)
),
verticalAlign: settings.verticalAlign,
editConfig: settings.isEditable
? {
Expand Down
2 changes: 1 addition & 1 deletion src/table/__tests__/table.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ test('should render table with react content', () => {
];
const { wrapper } = renderTable(<Table columnDefinitions={columns} items={defaultItems} />);
const findCellContent = (row: number, col: number) =>
wrapper.findBodyCell(row, col)!.findByClassName(bodyCellStyles['body-cell-content'])!;
wrapper.findBodyCell(row, col)!.findByClassName(bodyCellStyles['body-cell-content-inner'])!;
expect(wrapper.findColumnHeaders().map(getHeaderHtmlContent)).toEqual(['id', 'name', 'Advanced <span>header</span>']);
expect(wrapper.findRows()).toHaveLength(3);
expect(findCellContent(1, 3)!.getElement().innerHTML).toEqual('<input readonly="" value="Apples">');
Expand Down
14 changes: 11 additions & 3 deletions src/table/body-cell/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,17 @@ $cell-negative-space-vertical: 2px;

&-content {
box-sizing: border-box;
block-size: 100%;
display: flex;
align-items: center;

&.body-cell-align-top {
align-items: baseline;
}
}
&-content-inner {
box-sizing: border-box;
inline-size: 100%;

&:not(.body-cell-wrap) {
white-space: nowrap;
Expand Down Expand Up @@ -189,9 +200,6 @@ $cell-negative-space-vertical: 2px;
&:first-child:not(.is-visual-refresh) {
@include cell-padding-inline-start($cell-edge-horizontal-padding);
}
&-align-top {
vertical-align: top;
}
&-first-row {
border-block-start: $border-placeholder;
}
Expand Down
9 changes: 6 additions & 3 deletions src/table/body-cell/td-element.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const TableTdElement = React.forwardRef<HTMLTableCellElement, TableTdElem
const Element = isRowHeader ? 'th' : 'td';
const isVisualRefresh = useVisualRefresh();

resizableStyle = resizableColumns ? resizableStyle : {};
resizableStyle = resizableColumns ? {} : resizableStyle;

nativeAttributes = { ...nativeAttributes, ...getTableCellRoleProps({ tableRole, isRowHeader, colIndex }) };

Expand Down Expand Up @@ -139,7 +139,6 @@ export const TableTdElement = React.forwardRef<HTMLTableCellElement, TableTdElem
hasSuccessIcon && styles['body-cell-has-success'],
level !== undefined && styles['body-cell-expandable'],
level !== undefined && styles[`expandable-level-${getLevelClassSuffix(level)}`],
verticalAlign === 'top' && styles['body-cell-align-top'],
stickyStyles.className
)}
onClick={onClick}
Expand All @@ -161,7 +160,11 @@ export const TableTdElement = React.forwardRef<HTMLTableCellElement, TableTdElem
</div>
)}

<div className={clsx(styles['body-cell-content'], wrapLines && styles['body-cell-wrap'])}>{children}</div>
<div className={clsx(styles['body-cell-content'], verticalAlign === 'top' && styles['body-cell-align-top'])}>
<div className={clsx(styles['body-cell-content-inner'], wrapLines && styles['body-cell-wrap'])}>
{children}
</div>
</div>
</Element>
);
}
Expand Down
1 change: 1 addition & 0 deletions src/table/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

.table {
inline-size: 100%;
block-size: 100%;
border-spacing: 0;
position: relative;
box-sizing: border-box;
Expand Down

0 comments on commit b2a1194

Please sign in to comment.