Skip to content

Commit 0802626

Browse files
committed
fix last header cell className
ant-design/ant-design#20030
1 parent a22bdae commit 0802626

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

src/TableHeader.tsx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,41 @@ import {
1010
GetComponentProps,
1111
} from './interface';
1212

13-
function getHeaderRows(columns: InternalColumnType[], currentRow = 0, rows: Cell[][] = []) {
13+
function getHeaderRows({
14+
columns = [],
15+
currentRow = 0,
16+
rows = [],
17+
isLast = true,
18+
}: {
19+
columns?: InternalColumnType[];
20+
currentRow?: number;
21+
rows?: Cell[][];
22+
isLast?: boolean;
23+
}) {
1424
// eslint-disable-next-line no-param-reassign
1525
rows[currentRow] = rows[currentRow] || [];
1626

17-
columns.forEach(column => {
27+
columns.forEach((column, i) => {
1828
if (column.rowSpan && rows.length < column.rowSpan) {
1929
while (rows.length < column.rowSpan) {
2030
rows.push([]);
2131
}
2232
}
33+
const cellIsLast = isLast && i === columns.length - 1;
2334
const cell: Cell = {
2435
key: column.key,
2536
className: column.className || '',
2637
children: column.title,
38+
isLast: cellIsLast,
2739
column,
2840
};
2941
if (column.children) {
30-
getHeaderRows(column.children, currentRow + 1, rows);
42+
getHeaderRows({
43+
columns: column.children,
44+
currentRow: currentRow + 1,
45+
rows,
46+
isLast: cellIsLast,
47+
});
3148
}
3249
if ('colSpan' in column) {
3350
cell.colSpan = column.colSpan;
@@ -58,7 +75,7 @@ const TableHeader: React.FC<TableHeaderProps> = (props, { table }) => {
5875
return null;
5976
}
6077

61-
const rows = getHeaderRows(columns);
78+
const rows = getHeaderRows({ columns });
6279

6380
expander.renderExpandIndentCell(rows, fixed);
6481

src/TableHeaderRow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function TableHeaderRow({
4848
[`${prefixCls}-align-${column.align}`]: !!column.align,
4949
[`${prefixCls}-row-cell-ellipsis`]: !!column.ellipsis,
5050
[`${prefixCls}-row-cell-break-word`]: !!column.width,
51-
[`${prefixCls}-row-cell-last`]: i === row.length - 1,
51+
[`${prefixCls}-row-cell-last`]: cell.isLast,
5252
});
5353
return (
5454
<HeaderCell {...cellProps} {...customProps} key={column.key || column.dataIndex || i} />

src/interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export interface Cell {
4444
column?: ColumnType;
4545
colSpan?: number;
4646
rowSpan?: number;
47+
isLast?: boolean;
4748
}
4849

4950
export interface TableStoreState {

tests/__snapshots__/Table.spec.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ exports[`Table renders colSpan correctly 1`] = `
642642
>
643643
<tr>
644644
<th
645-
class="rc-table-row-cell-last"
645+
class=""
646646
colspan="2"
647647
>
648648
Name

0 commit comments

Comments
 (0)