From 356eb90aa9ff2479bb335e9ff04c9c97d36188ce Mon Sep 17 00:00:00 2001 From: lijianan <574980606@qq.com> Date: Sun, 4 Feb 2024 20:18:08 +0800 Subject: [PATCH] fix: change tag td => th (#1075) * fix: change tag td => th * fix: fix test case * lint: fix lint * test: fix test case --- src/Header/Header.tsx | 9 +++---- src/Header/HeaderRow.tsx | 25 +++++++++---------- tests/FixedColumn.spec.tsx | 4 +-- tests/Table.spec.jsx | 23 ----------------- tests/__snapshots__/ExpandRow.spec.jsx.snap | 10 ++++---- tests/__snapshots__/FixedColumn.spec.tsx.snap | 4 +-- tests/__snapshots__/Table.spec.jsx.snap | 10 ++++---- 7 files changed, 29 insertions(+), 56 deletions(-) diff --git a/src/Header/Header.tsx b/src/Header/Header.tsx index d7466d503..f21b817b2 100644 --- a/src/Header/Header.tsx +++ b/src/Header/Header.tsx @@ -90,7 +90,7 @@ export interface HeaderProps { onHeaderRow: GetComponentProps[]>; } -function Header(props: HeaderProps): React.ReactElement { +const Header = (props: HeaderProps) => { if (process.env.NODE_ENV !== 'production') { devRenderTimes(props); } @@ -98,12 +98,11 @@ function Header(props: HeaderProps): React.ReactElement const { stickyOffsets, columns, flattenColumns, onHeaderRow } = props; const { prefixCls, getComponent } = useContext(TableContext, ['prefixCls', 'getComponent']); - const rows: CellType[][] = React.useMemo(() => parseHeaderRows(columns), [columns]); + const rows = React.useMemo[][]>(() => parseHeaderRows(columns), [columns]); const WrapperComponent = getComponent(['header', 'wrapper'], 'thead'); const trComponent = getComponent(['header', 'row'], 'tr'); const thComponent = getComponent(['header', 'cell'], 'th'); - const tdComponent = getComponent(['header', 'cell'], 'td'); return ( @@ -116,16 +115,14 @@ function Header(props: HeaderProps): React.ReactElement stickyOffsets={stickyOffsets} rowComponent={trComponent} cellComponent={thComponent} - tdCellComponent={tdComponent} onHeaderRow={onHeaderRow} index={rowIndex} /> ); - return rowNode; })} ); -} +}; export default responseImmutable(Header); diff --git a/src/Header/HeaderRow.tsx b/src/Header/HeaderRow.tsx index 864dc0bc5..1a7dc4a72 100644 --- a/src/Header/HeaderRow.tsx +++ b/src/Header/HeaderRow.tsx @@ -18,21 +18,20 @@ export interface RowProps { flattenColumns: readonly ColumnType[]; rowComponent: CustomizeComponent; cellComponent: CustomizeComponent; - tdCellComponent: CustomizeComponent; onHeaderRow: GetComponentProps[]>; index: number; } -function HeaderRow({ - cells, - stickyOffsets, - flattenColumns, - rowComponent: RowComponent, - cellComponent: CellComponent, - tdCellComponent, - onHeaderRow, - index, -}: RowProps) { +const HeaderRow = (props: RowProps) => { + const { + cells, + stickyOffsets, + flattenColumns, + rowComponent: RowComponent, + cellComponent: CellComponent, + onHeaderRow, + index, + } = props; const { prefixCls, direction } = useContext(TableContext, ['prefixCls', 'direction']); let rowProps: React.HTMLAttributes; if (onHeaderRow) { @@ -68,7 +67,7 @@ function HeaderRow({ scope={column.title ? (cell.colSpan > 1 ? 'colgroup' : 'col') : null} ellipsis={column.ellipsis} align={column.align} - component={column.title ? CellComponent : tdCellComponent} + component={CellComponent} prefixCls={prefixCls} key={columnsKey[cellIndex]} {...fixedInfo} @@ -79,7 +78,7 @@ function HeaderRow({ })} ); -} +}; if (process.env.NODE_ENV !== 'production') { HeaderRow.displayName = 'HeaderRow'; diff --git a/tests/FixedColumn.spec.tsx b/tests/FixedColumn.spec.tsx index 7f252a396..d4168af12 100644 --- a/tests/FixedColumn.spec.tsx +++ b/tests/FixedColumn.spec.tsx @@ -276,10 +276,10 @@ describe('Table.FixedColumn', () => { }); expect(container.querySelectorAll('tbody .rc-table-cell-fix-left')).toHaveLength(2); - expect(container.querySelectorAll('thead td')[1]).toHaveStyle({ + expect(container.querySelectorAll('thead th')[1]).toHaveStyle({ left: '0px', }); - expect(container.querySelectorAll('thead td')[2]).toHaveStyle({ + expect(container.querySelectorAll('thead th')[2]).toHaveStyle({ left: '1000px', }); }); diff --git a/tests/Table.spec.jsx b/tests/Table.spec.jsx index 05b9d53aa..3201053eb 100644 --- a/tests/Table.spec.jsx +++ b/tests/Table.spec.jsx @@ -300,29 +300,6 @@ describe('Table.Basic', () => { }); }); - it('renders td instead of th if header title is empty', () => { - const wrapper = mount( - createTable({ - columns: [ - { - title: '', - dataIndex: 'firstName', - key: 'firstName', - }, - { - title: 'Last Name', - dataIndex: 'lastName', - key: 'lastName', - }, - ], - data: [{ firstName: 'John', lastName: 'Doe', key: '1' }], - }), - ); - - expect(wrapper.find('thead td')).toHaveLength(1); - expect(wrapper.find('thead th')).toHaveLength(1); - }); - it('renders column correctly', () => { const columns = [ { diff --git a/tests/__snapshots__/ExpandRow.spec.jsx.snap b/tests/__snapshots__/ExpandRow.spec.jsx.snap index 96f841d8f..08b694eff 100644 --- a/tests/__snapshots__/ExpandRow.spec.jsx.snap +++ b/tests/__snapshots__/ExpandRow.spec.jsx.snap @@ -159,7 +159,7 @@ LoadedCheerio { class="rc-table-thead" > - @@ -344,7 +344,7 @@ LoadedCheerio { class="rc-table-thead" > - @@ -646,7 +646,7 @@ LoadedCheerio { class="rc-table-thead" > - @@ -1204,7 +1204,7 @@ LoadedCheerio { class="rc-table-thead" > - @@ -1410,7 +1410,7 @@ LoadedCheerio { > Gender - diff --git a/tests/__snapshots__/FixedColumn.spec.tsx.snap b/tests/__snapshots__/FixedColumn.spec.tsx.snap index 05fa363c6..273f7f0c2 100644 --- a/tests/__snapshots__/FixedColumn.spec.tsx.snap +++ b/tests/__snapshots__/FixedColumn.spec.tsx.snap @@ -2068,7 +2068,7 @@ LoadedCheerio { > title12 - @@ -2941,7 +2941,7 @@ LoadedCheerio { > title12 - diff --git a/tests/__snapshots__/Table.spec.jsx.snap b/tests/__snapshots__/Table.spec.jsx.snap index 3dc5283f0..c3261a2ff 100644 --- a/tests/__snapshots__/Table.spec.jsx.snap +++ b/tests/__snapshots__/Table.spec.jsx.snap @@ -394,13 +394,13 @@ LoadedCheerio { class="rc-table-thead" > - - - @@ -1021,7 +1021,7 @@ LoadedCheerio { class="rc-table-thead" > - @@ -1212,7 +1212,7 @@ LoadedCheerio { > Name -