Skip to content

Commit

Permalink
fix last header cell className
Browse files Browse the repository at this point in the history
  • Loading branch information
afc163 committed Dec 2, 2019
1 parent a22bdae commit 0802626
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
25 changes: 21 additions & 4 deletions src/TableHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,41 @@ import {
GetComponentProps,
} from './interface';

function getHeaderRows(columns: InternalColumnType[], currentRow = 0, rows: Cell[][] = []) {
function getHeaderRows({
columns = [],
currentRow = 0,
rows = [],
isLast = true,
}: {
columns?: InternalColumnType[];
currentRow?: number;
rows?: Cell[][];
isLast?: boolean;
}) {
// eslint-disable-next-line no-param-reassign
rows[currentRow] = rows[currentRow] || [];

columns.forEach(column => {
columns.forEach((column, i) => {
if (column.rowSpan && rows.length < column.rowSpan) {
while (rows.length < column.rowSpan) {
rows.push([]);
}
}
const cellIsLast = isLast && i === columns.length - 1;
const cell: Cell = {
key: column.key,
className: column.className || '',
children: column.title,
isLast: cellIsLast,
column,
};
if (column.children) {
getHeaderRows(column.children, currentRow + 1, rows);
getHeaderRows({
columns: column.children,
currentRow: currentRow + 1,
rows,
isLast: cellIsLast,
});
}
if ('colSpan' in column) {
cell.colSpan = column.colSpan;
Expand Down Expand Up @@ -58,7 +75,7 @@ const TableHeader: React.FC<TableHeaderProps> = (props, { table }) => {
return null;
}

const rows = getHeaderRows(columns);
const rows = getHeaderRows({ columns });

expander.renderExpandIndentCell(rows, fixed);

Expand Down
2 changes: 1 addition & 1 deletion src/TableHeaderRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function TableHeaderRow({
[`${prefixCls}-align-${column.align}`]: !!column.align,
[`${prefixCls}-row-cell-ellipsis`]: !!column.ellipsis,
[`${prefixCls}-row-cell-break-word`]: !!column.width,
[`${prefixCls}-row-cell-last`]: i === row.length - 1,
[`${prefixCls}-row-cell-last`]: cell.isLast,
});
return (
<HeaderCell {...cellProps} {...customProps} key={column.key || column.dataIndex || i} />
Expand Down
1 change: 1 addition & 0 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface Cell {
column?: ColumnType;
colSpan?: number;
rowSpan?: number;
isLast?: boolean;
}

export interface TableStoreState {
Expand Down
2 changes: 1 addition & 1 deletion tests/__snapshots__/Table.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ exports[`Table renders colSpan correctly 1`] = `
>
<tr>
<th
class="rc-table-row-cell-last"
class=""
colspan="2"
>
Name
Expand Down

0 comments on commit 0802626

Please sign in to comment.