Skip to content

Commit 89ab5b7

Browse files
committed
refactor: hide original thead
1 parent 440edfa commit 89ab5b7

File tree

6 files changed

+133
-80
lines changed

6 files changed

+133
-80
lines changed

packages/components/table/BaseTable.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ const BaseTable = forwardRef<BaseTableRef, BaseTableProps>((originalProps, ref)
306306
})}
307307
</colgroup>
308308
);
309+
310+
const theadStyle = useMemo(() => (showAffixHeader ? { opacity: 0 } : undefined), [showAffixHeader]);
311+
309312
const headProps: TheadProps = {
310313
isFixedHeader,
311314
rowAndColFixedPosition,
@@ -338,6 +341,7 @@ const BaseTable = forwardRef<BaseTableRef, BaseTableProps>((originalProps, ref)
338341
props.bordered,
339342
props.resizable,
340343
props.size,
344+
theadStyle,
341345
];
342346

343347
// 多级表头左边线缺失
@@ -518,7 +522,7 @@ const BaseTable = forwardRef<BaseTableRef, BaseTableProps>((originalProps, ref)
518522
{renderColGroup(false)}
519523
{useMemo(() => {
520524
if (!showHeader) return null;
521-
return <THead {...{ ...headProps, thWidthList: resizable ? thWidthList.current : {} }} />;
525+
return <THead {...{ ...headProps, theadStyle, thWidthList: resizable ? thWidthList.current : {} }} />;
522526
// eslint-disable-next-line
523527
}, headUseMemoDependencies)}
524528

packages/components/table/THead.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
import React, { useRef, MutableRefObject, CSSProperties, useMemo } from 'react';
2-
import { isFunction } from 'lodash-es';
1+
import React, { CSSProperties, MutableRefObject, useMemo, useRef } from 'react';
32
import classNames from 'classnames';
4-
import { getColumnFixedStyles } from './hooks/useFixed';
5-
import { RowAndColFixedPosition } from './interface';
6-
import { TableColumns, ThRowspanAndColspan } from './hooks/useMultiHeader';
3+
import { isFunction } from 'lodash-es';
4+
5+
import TEllipsis from './Ellipsis';
76
import useClassName from './hooks/useClassName';
8-
import { BaseTableCol, TableRowData, TdBaseTableProps } from './type';
7+
import { getColumnFixedStyles } from './hooks/useFixed';
98
import { renderTitle } from './hooks/useTableHeader';
10-
import TEllipsis from './Ellipsis';
119
import { formatClassNames } from './utils';
12-
import { AttachNode } from '../common';
10+
11+
import type { AttachNode } from '../common';
12+
import type { TableColumns, ThRowspanAndColspan } from './hooks/useMultiHeader';
13+
import type { RowAndColFixedPosition } from './interface';
14+
import type { BaseTableCol, TableRowData, TdBaseTableProps } from './type';
1315

1416
export interface TheadProps {
1517
classPrefix: string;
@@ -33,6 +35,7 @@ export interface TheadProps {
3335
resizable?: boolean;
3436
attach?: AttachNode;
3537
showColumnShadow?: { left: boolean; right: boolean };
38+
theadStyle?: CSSProperties;
3639
columnResizeParams?: {
3740
resizeLineRef: MutableRefObject<HTMLDivElement>;
3841
resizeLineStyle: CSSProperties;
@@ -195,7 +198,7 @@ export default function THead(props: TheadProps) {
195198
};
196199

197200
return (
198-
<thead ref={theadRef} className={classNames(theadClasses)}>
201+
<thead ref={theadRef} className={classNames(theadClasses)} style={props.theadStyle}>
199202
{renderThNodeList(props.rowAndColFixedPosition, props.thWidthList)}
200203
</thead>
201204
);

packages/components/table/__tests__/__snapshots__/pagination.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ exports[`BaseTable Pagination > locale data pagination controlled > pagination.c
160160
</colgroup>
161161
<thead
162162
class="t-table__header"
163+
style="opacity: 0;"
163164
>
164165
<tr>
165166
<th

packages/components/table/__tests__/__snapshots__/vitest-table.test.jsx.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ exports[`BaseTable Component > props.showHeader: BaseTable contains element \`th
2525
</colgroup>
2626
<thead
2727
class="t-table__header"
28+
style="opacity: 0;"
2829
>
2930
<tr>
3031
<th
@@ -180,6 +181,7 @@ exports[`BaseTable Component > props.size is equal to large 1`] = `
180181
</colgroup>
181182
<thead
182183
class="t-table__header"
184+
style="opacity: 0;"
183185
>
184186
<tr>
185187
<th
@@ -335,6 +337,7 @@ exports[`BaseTable Component > props.size is equal to medium 1`] = `
335337
</colgroup>
336338
<thead
337339
class="t-table__header"
340+
style="opacity: 0;"
338341
>
339342
<tr>
340343
<th
@@ -490,6 +493,7 @@ exports[`BaseTable Component > props.size is equal to small 1`] = `
490493
</colgroup>
491494
<thead
492495
class="t-table__header"
496+
style="opacity: 0;"
493497
>
494498
<tr>
495499
<th
@@ -639,6 +643,7 @@ exports[`BaseTable Component > props.tableLayout is equal to auto 1`] = `
639643
</colgroup>
640644
<thead
641645
class="t-table__header"
646+
style="opacity: 0;"
642647
>
643648
<tr>
644649
<th
@@ -794,6 +799,7 @@ exports[`BaseTable Component > props.tableLayout is equal to fixed 1`] = `
794799
</colgroup>
795800
<thead
796801
class="t-table__header"
802+
style="opacity: 0;"
797803
>
798804
<tr>
799805
<th

0 commit comments

Comments
 (0)