Skip to content

Commit 3efc943

Browse files
authored
fix: avoiding closure problems
avoiding closure problems
1 parent 5599e70 commit 3efc943

File tree

2 files changed

+20
-27
lines changed

2 files changed

+20
-27
lines changed

docs/examples/measureRowRender.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,14 @@ const data = [
3131
];
3232

3333
// 自定义 MeasureRow 渲染,隐藏弹层内容
34-
const measureRowRender: TableProps['measureRowRender'] = measureRow => (
35-
<div style={{ display: 'none' }}>{measureRow}</div>
36-
);
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+
};
3742

3843
// 示例:使用 measureRowRender 来隐藏 MeasureRow 中的弹层
3944
const MeasureRowRenderExample: React.FC = () => {

src/FixedHolder/index.tsx

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -157,31 +157,13 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<any>>((pro
157157

158158
const mergedColumnWidth = useColumnWidth(colWidths, columCount);
159159

160-
const colGroupNode = useMemo(() => {
160+
const isColGroupEmpty = useMemo<boolean>(() => {
161161
// use original ColGroup if no data or no calculated column width, otherwise use calculated column width
162162
// Return original colGroup if no data, or mergedColumnWidth is empty, or all widths are falsy
163-
if (
164-
noData ||
165-
!mergedColumnWidth ||
166-
mergedColumnWidth.length === 0 ||
167-
mergedColumnWidth.every(width => !width)
168-
) {
169-
return ColGroup;
170-
}
171-
return (
172-
<ColGroup
173-
colWidths={[...mergedColumnWidth, combinationScrollBarSize]}
174-
columCount={columCount + 1}
175-
columns={flattenColumnsWithScrollbar}
176-
/>
177-
);
178-
}, [
179-
noData,
180-
mergedColumnWidth,
181-
combinationScrollBarSize,
182-
columCount,
183-
flattenColumnsWithScrollbar,
184-
]);
163+
const noWidth =
164+
!mergedColumnWidth || !mergedColumnWidth.length || mergedColumnWidth.every(w => !w);
165+
return noData || noWidth;
166+
}, [noData, mergedColumnWidth]);
185167

186168
return (
187169
<div
@@ -203,7 +185,13 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<any>>((pro
203185
width: scrollX,
204186
}}
205187
>
206-
{colGroupNode}
188+
{isColGroupEmpty ? null : (
189+
<ColGroup
190+
colWidths={[...mergedColumnWidth, combinationScrollBarSize]}
191+
columCount={columCount + 1}
192+
columns={flattenColumnsWithScrollbar}
193+
/>
194+
)}
207195
{children({
208196
...restProps,
209197
stickyOffsets: headerStickyOffsets,

0 commit comments

Comments
 (0)