Skip to content

Commit 356eb90

Browse files
authored
fix: change tag td => th (#1075)
* fix: change tag td => th * fix: fix test case * lint: fix lint * test: fix test case
1 parent f9e7c88 commit 356eb90

File tree

7 files changed

+29
-56
lines changed

7 files changed

+29
-56
lines changed

src/Header/Header.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,19 @@ export interface HeaderProps<RecordType> {
9090
onHeaderRow: GetComponentProps<readonly ColumnType<RecordType>[]>;
9191
}
9292

93-
function Header<RecordType>(props: HeaderProps<RecordType>): React.ReactElement {
93+
const Header = <RecordType extends any>(props: HeaderProps<RecordType>) => {
9494
if (process.env.NODE_ENV !== 'production') {
9595
devRenderTimes(props);
9696
}
9797

9898
const { stickyOffsets, columns, flattenColumns, onHeaderRow } = props;
9999

100100
const { prefixCls, getComponent } = useContext(TableContext, ['prefixCls', 'getComponent']);
101-
const rows: CellType<RecordType>[][] = React.useMemo(() => parseHeaderRows(columns), [columns]);
101+
const rows = React.useMemo<CellType<RecordType>[][]>(() => parseHeaderRows(columns), [columns]);
102102

103103
const WrapperComponent = getComponent(['header', 'wrapper'], 'thead');
104104
const trComponent = getComponent(['header', 'row'], 'tr');
105105
const thComponent = getComponent(['header', 'cell'], 'th');
106-
const tdComponent = getComponent(['header', 'cell'], 'td');
107106

108107
return (
109108
<WrapperComponent className={`${prefixCls}-thead`}>
@@ -116,16 +115,14 @@ function Header<RecordType>(props: HeaderProps<RecordType>): React.ReactElement
116115
stickyOffsets={stickyOffsets}
117116
rowComponent={trComponent}
118117
cellComponent={thComponent}
119-
tdCellComponent={tdComponent}
120118
onHeaderRow={onHeaderRow}
121119
index={rowIndex}
122120
/>
123121
);
124-
125122
return rowNode;
126123
})}
127124
</WrapperComponent>
128125
);
129-
}
126+
};
130127

131128
export default responseImmutable(Header);

src/Header/HeaderRow.tsx

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,20 @@ export interface RowProps<RecordType> {
1818
flattenColumns: readonly ColumnType<RecordType>[];
1919
rowComponent: CustomizeComponent;
2020
cellComponent: CustomizeComponent;
21-
tdCellComponent: CustomizeComponent;
2221
onHeaderRow: GetComponentProps<readonly ColumnType<RecordType>[]>;
2322
index: number;
2423
}
2524

26-
function HeaderRow<RecordType>({
27-
cells,
28-
stickyOffsets,
29-
flattenColumns,
30-
rowComponent: RowComponent,
31-
cellComponent: CellComponent,
32-
tdCellComponent,
33-
onHeaderRow,
34-
index,
35-
}: RowProps<RecordType>) {
25+
const HeaderRow = <RecordType extends any>(props: RowProps<RecordType>) => {
26+
const {
27+
cells,
28+
stickyOffsets,
29+
flattenColumns,
30+
rowComponent: RowComponent,
31+
cellComponent: CellComponent,
32+
onHeaderRow,
33+
index,
34+
} = props;
3635
const { prefixCls, direction } = useContext(TableContext, ['prefixCls', 'direction']);
3736
let rowProps: React.HTMLAttributes<HTMLElement>;
3837
if (onHeaderRow) {
@@ -68,7 +67,7 @@ function HeaderRow<RecordType>({
6867
scope={column.title ? (cell.colSpan > 1 ? 'colgroup' : 'col') : null}
6968
ellipsis={column.ellipsis}
7069
align={column.align}
71-
component={column.title ? CellComponent : tdCellComponent}
70+
component={CellComponent}
7271
prefixCls={prefixCls}
7372
key={columnsKey[cellIndex]}
7473
{...fixedInfo}
@@ -79,7 +78,7 @@ function HeaderRow<RecordType>({
7978
})}
8079
</RowComponent>
8180
);
82-
}
81+
};
8382

8483
if (process.env.NODE_ENV !== 'production') {
8584
HeaderRow.displayName = 'HeaderRow';

tests/FixedColumn.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,10 @@ describe('Table.FixedColumn', () => {
276276
});
277277

278278
expect(container.querySelectorAll('tbody .rc-table-cell-fix-left')).toHaveLength(2);
279-
expect(container.querySelectorAll('thead td')[1]).toHaveStyle({
279+
expect(container.querySelectorAll('thead th')[1]).toHaveStyle({
280280
left: '0px',
281281
});
282-
expect(container.querySelectorAll('thead td')[2]).toHaveStyle({
282+
expect(container.querySelectorAll('thead th')[2]).toHaveStyle({
283283
left: '1000px',
284284
});
285285
});

tests/Table.spec.jsx

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -300,29 +300,6 @@ describe('Table.Basic', () => {
300300
});
301301
});
302302

303-
it('renders td instead of th if header title is empty', () => {
304-
const wrapper = mount(
305-
createTable({
306-
columns: [
307-
{
308-
title: '',
309-
dataIndex: 'firstName',
310-
key: 'firstName',
311-
},
312-
{
313-
title: 'Last Name',
314-
dataIndex: 'lastName',
315-
key: 'lastName',
316-
},
317-
],
318-
data: [{ firstName: 'John', lastName: 'Doe', key: '1' }],
319-
}),
320-
);
321-
322-
expect(wrapper.find('thead td')).toHaveLength(1);
323-
expect(wrapper.find('thead th')).toHaveLength(1);
324-
});
325-
326303
it('renders column correctly', () => {
327304
const columns = [
328305
{

tests/__snapshots__/ExpandRow.spec.jsx.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ LoadedCheerio {
159159
class="rc-table-thead"
160160
>
161161
<tr>
162-
<td
162+
<th
163163
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix-left rc-table-cell-fix-left-last"
164164
style="position: sticky; left: 0px;"
165165
/>
@@ -344,7 +344,7 @@ LoadedCheerio {
344344
class="rc-table-thead"
345345
>
346346
<tr>
347-
<td
347+
<th
348348
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix-left rc-table-cell-fix-left-last"
349349
style="position: sticky; left: 0px;"
350350
/>
@@ -646,7 +646,7 @@ LoadedCheerio {
646646
class="rc-table-thead"
647647
>
648648
<tr>
649-
<td
649+
<th
650650
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix-left"
651651
style="position: sticky; left: 0px;"
652652
/>
@@ -1204,7 +1204,7 @@ LoadedCheerio {
12041204
class="rc-table-thead"
12051205
>
12061206
<tr>
1207-
<td
1207+
<th
12081208
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix-left rc-table-cell-fix-left-last"
12091209
style="position: sticky; left: 0px;"
12101210
/>
@@ -1410,7 +1410,7 @@ LoadedCheerio {
14101410
>
14111411
Gender
14121412
</th>
1413-
<td
1413+
<th
14141414
class="rc-table-cell rc-table-row-expand-icon-cell rc-table-cell-fix-right rc-table-cell-fix-right-first"
14151415
style="position: sticky; right: 0px;"
14161416
/>

tests/__snapshots__/FixedColumn.spec.tsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,7 +2068,7 @@ LoadedCheerio {
20682068
>
20692069
title12
20702070
</th>
2071-
<td
2071+
<th
20722072
class="rc-table-cell rc-table-cell-fix-right rc-table-cell-scrollbar"
20732073
style="position: sticky; right: 0px;"
20742074
/>
@@ -2941,7 +2941,7 @@ LoadedCheerio {
29412941
>
29422942
title12
29432943
</th>
2944-
<td
2944+
<th
29452945
class="rc-table-cell rc-table-cell-fix-right rc-table-cell-scrollbar"
29462946
style="position: sticky; right: 0px;"
29472947
/>

tests/__snapshots__/Table.spec.jsx.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -394,13 +394,13 @@ LoadedCheerio {
394394
class="rc-table-thead"
395395
>
396396
<tr>
397-
<td
397+
<th
398398
class="rc-table-cell"
399399
/>
400-
<td
400+
<th
401401
class="rc-table-cell"
402402
/>
403-
<td
403+
<th
404404
class="rc-table-cell rc-table-cell-scrollbar"
405405
/>
406406
</tr>
@@ -1021,7 +1021,7 @@ LoadedCheerio {
10211021
class="rc-table-thead"
10221022
>
10231023
<tr>
1024-
<td
1024+
<th
10251025
class="rc-table-cell"
10261026
/>
10271027
</tr>
@@ -1212,7 +1212,7 @@ LoadedCheerio {
12121212
>
12131213
Name
12141214
</th>
1215-
<td
1215+
<th
12161216
class="rc-table-cell rc-table-cell-scrollbar"
12171217
/>
12181218
</tr>

0 commit comments

Comments
 (0)