Skip to content

Commit 696680c

Browse files
committed
chore: sync master into 5.x
1 parent 25fb5a1 commit 696680c

File tree

4 files changed

+58
-54
lines changed

4 files changed

+58
-54
lines changed

docs/demo/measureRowRender.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: measureRowRender
3+
nav:
4+
title: measureRowRender
5+
path: /demo
6+
---
7+
8+
<code src="../examples/measureRowRender.tsx"></code>

docs/examples/measureRowRender.tsx

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,47 @@
11
import React from 'react';
22
import Table from 'rc-table';
3+
import type { TableProps } from 'rc-table';
34

4-
// 示例:使用 measureRowRender 来隐藏 MeasureRow 中的弹层
5-
const MeasureRowRenderExample = () => {
6-
const columns = [
7-
{
8-
title: (
9-
<div>
10-
Name
11-
<div className="filter-dropdown" style={{ display: 'none' }}>
12-
Filter Content
13-
</div>
5+
const columns = [
6+
{
7+
title: (
8+
<div>
9+
Name
10+
<div className="filter-dropdown" style={{ display: 'none' }}>
11+
Filter Content
1412
</div>
15-
),
16-
dataIndex: 'name',
17-
key: 'name',
18-
width: 100,
19-
},
20-
{
21-
title: 'Age',
22-
dataIndex: 'age',
23-
key: 'age',
24-
width: 80,
25-
},
26-
];
13+
</div>
14+
),
15+
dataIndex: 'name',
16+
key: 'name',
17+
width: 100,
18+
},
19+
{
20+
title: 'Age',
21+
dataIndex: 'age',
22+
key: 'age',
23+
width: 80,
24+
},
25+
];
2726

28-
const data = [
29-
{ key: 1, name: 'John', age: 25 },
30-
{ key: 2, name: 'Jane', age: 30 },
31-
];
27+
const data = [
28+
{ key: 1, name: 'John', age: 25 },
29+
{ key: 2, name: 'Jane', age: 30 },
30+
{ key: 3, name: 'Jime', age: 35 },
31+
];
3232

33-
// 自定义 MeasureRow 渲染,隐藏弹层内容
34-
const measureRowRender = measureRow => <div style={{ display: 'none' }}>{measureRow}</div>;
33+
// 自定义 MeasureRow 渲染,隐藏弹层内容
34+
const measureRowRender: TableProps['measureRowRender'] = measureRow => {
35+
if (React.isValidElement(measureRow)) {
36+
return React.cloneElement<any>(measureRow, {
37+
style: { ...(measureRow.props as any).style, display: 'none' },
38+
});
39+
}
40+
return measureRow;
41+
};
3542

43+
// 示例:使用 measureRowRender 来隐藏 MeasureRow 中的弹层
44+
const MeasureRowRenderExample: React.FC = () => {
3645
return (
3746
<Table
3847
columns={columns}

src/FixedHolder/index.tsx

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -137,32 +137,13 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<any>>((pro
137137

138138
const mergedColumnWidth = useColumnWidth(colWidths, columCount);
139139

140-
const colGroupNode = useMemo(() => {
140+
const isColGroupEmpty = useMemo<boolean>(() => {
141141
// use original ColGroup if no data or no calculated column width, otherwise use calculated column width
142142
// Return original colGroup if no data, or mergedColumnWidth is empty, or all widths are falsy
143-
if (
144-
noData ||
145-
!mergedColumnWidth ||
146-
mergedColumnWidth.length === 0 ||
147-
mergedColumnWidth.every(width => !width)
148-
) {
149-
return colGroup;
150-
}
151-
return (
152-
<ColGroup
153-
colWidths={[...mergedColumnWidth, combinationScrollBarSize]}
154-
columCount={columCount + 1}
155-
columns={flattenColumnsWithScrollbar}
156-
/>
157-
);
158-
}, [
159-
noData,
160-
mergedColumnWidth,
161-
colGroup,
162-
combinationScrollBarSize,
163-
columCount,
164-
flattenColumnsWithScrollbar,
165-
]);
143+
const noWidth =
144+
!mergedColumnWidth || !mergedColumnWidth.length || mergedColumnWidth.every(w => !w);
145+
return noData || noWidth;
146+
}, [noData, mergedColumnWidth]);
166147

167148
return (
168149
<div
@@ -183,7 +164,13 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<any>>((pro
183164
width: scrollX,
184165
}}
185166
>
186-
{colGroupNode}
167+
{isColGroupEmpty ? null : (
168+
<ColGroup
169+
colWidths={[...mergedColumnWidth, combinationScrollBarSize]}
170+
columCount={columCount + 1}
171+
columns={flattenColumnsWithScrollbar}
172+
/>
173+
)}
187174
{children({
188175
...restProps,
189176
stickyOffsets: headerStickyOffsets,

src/interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ type Component<P> =
143143
| React.ComponentType<P>
144144
| React.ForwardRefExoticComponent<P>
145145
| React.FC<P>
146-
| keyof React.ReactHTML;
146+
| keyof React.JSX.IntrinsicElements;
147147

148148
export type CustomizeComponent = Component<any>;
149149

0 commit comments

Comments
 (0)