Skip to content

Commit 7911c8d

Browse files
Linkodtafc163
authored andcommitted
fix: Table MeasureRow bug when children have refs
1 parent 313b619 commit 7911c8d

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

src/Body/MeasureCell.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import type { ColumnType } from '../interface';
66
export interface MeasureCellProps {
77
columnKey: React.Key;
88
onColumnResize: (key: React.Key, width: number) => void;
9-
column?: ColumnType<any>;
109
prefixCls: string;
10+
title?: React.ReactNode;
1111
}
1212

1313
export default function MeasureCell({
1414
columnKey,
1515
onColumnResize,
16-
column,
1716
prefixCls,
17+
title,
1818
}: MeasureCellProps) {
1919
const cellRef = React.useRef<HTMLTableCellElement>();
2020

@@ -27,7 +27,7 @@ export default function MeasureCell({
2727
return (
2828
<ResizeObserver data={columnKey}>
2929
<th ref={cellRef} className={`${prefixCls}-measure-cell`}>
30-
<div className={`${prefixCls}-measure-cell-content`}>{column?.title || '\xa0'}</div>
30+
<div className={`${prefixCls}-measure-cell-content`}>{title || '\xa0'}</div>
3131
</th>
3232
</ResizeObserver>
3333
);

src/Body/MeasureRow.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,17 @@ export default function MeasureRow({
3535
>
3636
{columnsKey.map(columnKey => {
3737
const column = columns.find(col => col.key === columnKey);
38+
const rawTitle = column?.title;
39+
const titleForMeasure = React.isValidElement<React.RefAttributes<any>>(rawTitle)
40+
? React.cloneElement(rawTitle, { ref: null })
41+
: rawTitle;
3842
return (
3943
<MeasureCell
4044
prefixCls={prefixCls}
4145
key={columnKey}
4246
columnKey={columnKey}
4347
onColumnResize={onColumnResize}
44-
column={column}
48+
title={titleForMeasure}
4549
/>
4650
);
4751
})}

0 commit comments

Comments
 (0)