diff --git a/src/Body/index.tsx b/src/Body/index.tsx index fed61a97b..6fb7dcbbd 100644 --- a/src/Body/index.tsx +++ b/src/Body/index.tsx @@ -8,7 +8,8 @@ import ResizeContext from '../context/ResizeContext'; import BodyRow from './BodyRow'; import useFlattenRecords from '../hooks/useFlattenRecords'; import HoverContext from '../context/HoverContext'; -import PerfContext, { PerfRecord } from '../context/PerfContext'; +import type { PerfRecord } from '../context/PerfContext'; +import PerfContext from '../context/PerfContext'; import MeasureRow from './MeasureRow'; export interface BodyProps { diff --git a/src/Cell/index.tsx b/src/Cell/index.tsx index a02a44c00..6a98c135b 100644 --- a/src/Cell/index.tsx +++ b/src/Cell/index.tsx @@ -86,6 +86,23 @@ export type CellProps = Omit< keyof HoverContextProps >; +const getTitleFromCellRenderChildren = ({ + ellipsis, + rowType, + children, +}: Pick, 'ellipsis' | 'rowType' | 'children'>) => { + let title: string; + const ellipsisConfig: CellEllipsisType = ellipsis === true ? { showTitle: true } : ellipsis; + if (ellipsisConfig && (ellipsisConfig.showTitle || rowType === 'header')) { + if (typeof children === 'string' || typeof children === 'number') { + title = children.toString(); + } else if (React.isValidElement(children) && typeof children.props.children === 'string') { + title = children.props.children; + } + } + return title; +}; + function Cell( { prefixCls, @@ -132,7 +149,10 @@ function Cell( return [children]; } - const value = getPathValue(record, dataIndex); + const value = getPathValue | React.ReactNode, RecordType>( + record, + dataIndex, + ); // Customize render node let returnChildNode = value; @@ -238,18 +258,11 @@ function Cell( }; // ====================== Render ====================== - let title: string; - const ellipsisConfig: CellEllipsisType = ellipsis === true ? { showTitle: true } : ellipsis; - if (ellipsisConfig && (ellipsisConfig.showTitle || rowType === 'header')) { - if (typeof mergedChildNode === 'string' || typeof mergedChildNode === 'number') { - title = mergedChildNode.toString(); - } else if ( - React.isValidElement(mergedChildNode) && - typeof mergedChildNode.props.children === 'string' - ) { - title = mergedChildNode.props.children; - } - } + const title = getTitleFromCellRenderChildren({ + rowType, + ellipsis, + children: childNode, + }); const componentProps: React.TdHTMLAttributes & { ref: React.Ref; diff --git a/tests/FixedColumn.spec.js b/tests/FixedColumn.spec.js index eb53648bb..11078100e 100644 --- a/tests/FixedColumn.spec.js +++ b/tests/FixedColumn.spec.js @@ -21,7 +21,15 @@ describe('Table.FixedColumn', () => { const columns = [ { title: 'title1', dataIndex: 'a', key: 'a', width: 100, fixed: 'left' }, - { title: 'title2', dataIndex: 'b', key: 'b', width: 100, fixed: 'left' }, + { + title: 'title2', + dataIndex: 'b', + key: 'b', + width: 100, + fixed: 'left', + ellipsis: true, + render: () => 1111, + }, { title: 'title3', dataIndex: 'c', key: 'c' }, { title: 'title4', dataIndex: 'b', key: 'd' }, { title: 'title5', dataIndex: 'b', key: 'e' }, diff --git a/tests/__snapshots__/FixedColumn.spec.js.snap b/tests/__snapshots__/FixedColumn.spec.js.snap index b245c9ff6..5de632df2 100644 --- a/tests/__snapshots__/FixedColumn.spec.js.snap +++ b/tests/__snapshots__/FixedColumn.spec.js.snap @@ -45,8 +45,9 @@ exports[`Table.FixedColumn fixed column renders correctly RTL 1`] = ` title1 title2 @@ -231,10 +232,13 @@ exports[`Table.FixedColumn fixed column renders correctly RTL 1`] = ` 123 - xxxxxxxx + + 1111 + - edd12221 + + 1111 + + title="1111" + > + + 1111 + + @@ -411,9 +423,14 @@ exports[`Table.FixedColumn fixed column renders correctly RTL 1`] = ` 133 + title="1111" + > + + 1111 + + @@ -459,9 +476,14 @@ exports[`Table.FixedColumn fixed column renders correctly RTL 1`] = ` 133 + title="1111" + > + + 1111 + + @@ -507,9 +529,14 @@ exports[`Table.FixedColumn fixed column renders correctly RTL 1`] = ` 133 + title="1111" + > + + 1111 + + @@ -555,9 +582,14 @@ exports[`Table.FixedColumn fixed column renders correctly RTL 1`] = ` 133 + title="1111" + > + + 1111 + + @@ -603,9 +635,14 @@ exports[`Table.FixedColumn fixed column renders correctly RTL 1`] = ` 133 + title="1111" + > + + 1111 + + @@ -651,9 +688,14 @@ exports[`Table.FixedColumn fixed column renders correctly RTL 1`] = ` 133 + title="1111" + > + + 1111 + + @@ -751,10 +793,15 @@ exports[`Table.FixedColumn renders correctly scrollX - with data 1`] = ` title1 - title2 + + title2 + - xxxxxxxx + + + 1111 + + - edd12221 + + + 1111 + + + title="1111" + > + + + 1111 + + + @@ -1117,9 +1187,18 @@ exports[`Table.FixedColumn renders correctly scrollX - with data 1`] = ` 133 + title="1111" + > + + + 1111 + + + @@ -1165,9 +1244,18 @@ exports[`Table.FixedColumn renders correctly scrollX - with data 1`] = ` 133 + title="1111" + > + + + 1111 + + + @@ -1213,9 +1301,18 @@ exports[`Table.FixedColumn renders correctly scrollX - with data 1`] = ` 133 + title="1111" + > + + + 1111 + + + @@ -1261,9 +1358,18 @@ exports[`Table.FixedColumn renders correctly scrollX - with data 1`] = ` 133 + title="1111" + > + + + 1111 + + + @@ -1309,9 +1415,18 @@ exports[`Table.FixedColumn renders correctly scrollX - with data 1`] = ` 133 + title="1111" + > + + + 1111 + + + @@ -1357,9 +1472,18 @@ exports[`Table.FixedColumn renders correctly scrollX - with data 1`] = ` 133 + title="1111" + > + + + 1111 + + + @@ -1446,10 +1570,15 @@ exports[`Table.FixedColumn renders correctly scrollX - without data 1`] = ` title1 - title2 + + title2 + - title2 + + title2 + - xxxxxxxx + + + 1111 + + - edd12221 + + + 1111 + + + title="1111" + > + + + 1111 + + + @@ -2108,9 +2265,18 @@ exports[`Table.FixedColumn renders correctly scrollXY - with data 1`] = ` 133 + title="1111" + > + + + 1111 + + + @@ -2156,9 +2322,18 @@ exports[`Table.FixedColumn renders correctly scrollXY - with data 1`] = ` 133 + title="1111" + > + + + 1111 + + + @@ -2204,9 +2379,18 @@ exports[`Table.FixedColumn renders correctly scrollXY - with data 1`] = ` 133 + title="1111" + > + + + 1111 + + + @@ -2252,9 +2436,18 @@ exports[`Table.FixedColumn renders correctly scrollXY - with data 1`] = ` 133 + title="1111" + > + + + 1111 + + + @@ -2300,9 +2493,18 @@ exports[`Table.FixedColumn renders correctly scrollXY - with data 1`] = ` 133 + title="1111" + > + + + 1111 + + + @@ -2348,9 +2550,18 @@ exports[`Table.FixedColumn renders correctly scrollXY - with data 1`] = ` 133 + title="1111" + > + + + 1111 + + + @@ -2458,10 +2669,15 @@ exports[`Table.FixedColumn renders correctly scrollXY - without data 1`] = ` title1 - title2 + + title2 +