Skip to content

Commit 1d155cf

Browse files
authored
fix: ellipsis cell title lost when is last fixed column (#757)
* fix: fixed cell title lost close ant-design/ant-design#34208 * fix eslint * add test case
1 parent 312b95b commit 1d155cf

File tree

4 files changed

+316
-78
lines changed

4 files changed

+316
-78
lines changed

src/Body/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import ResizeContext from '../context/ResizeContext';
88
import BodyRow from './BodyRow';
99
import useFlattenRecords from '../hooks/useFlattenRecords';
1010
import HoverContext from '../context/HoverContext';
11-
import PerfContext, { PerfRecord } from '../context/PerfContext';
11+
import type { PerfRecord } from '../context/PerfContext';
12+
import PerfContext from '../context/PerfContext';
1213
import MeasureRow from './MeasureRow';
1314

1415
export interface BodyProps<RecordType> {

src/Cell/index.tsx

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,23 @@ export type CellProps<RecordType extends DefaultRecordType> = Omit<
8686
keyof HoverContextProps
8787
>;
8888

89+
const getTitleFromCellRenderChildren = ({
90+
ellipsis,
91+
rowType,
92+
children,
93+
}: Pick<InternalCellProps<any>, 'ellipsis' | 'rowType' | 'children'>) => {
94+
let title: string;
95+
const ellipsisConfig: CellEllipsisType = ellipsis === true ? { showTitle: true } : ellipsis;
96+
if (ellipsisConfig && (ellipsisConfig.showTitle || rowType === 'header')) {
97+
if (typeof children === 'string' || typeof children === 'number') {
98+
title = children.toString();
99+
} else if (React.isValidElement(children) && typeof children.props.children === 'string') {
100+
title = children.props.children;
101+
}
102+
}
103+
return title;
104+
};
105+
89106
function Cell<RecordType extends DefaultRecordType>(
90107
{
91108
prefixCls,
@@ -132,7 +149,10 @@ function Cell<RecordType extends DefaultRecordType>(
132149
return [children];
133150
}
134151

135-
const value = getPathValue<object | React.ReactNode, RecordType>(record, dataIndex);
152+
const value = getPathValue<Record<string, unknown> | React.ReactNode, RecordType>(
153+
record,
154+
dataIndex,
155+
);
136156

137157
// Customize render node
138158
let returnChildNode = value;
@@ -238,18 +258,11 @@ function Cell<RecordType extends DefaultRecordType>(
238258
};
239259

240260
// ====================== Render ======================
241-
let title: string;
242-
const ellipsisConfig: CellEllipsisType = ellipsis === true ? { showTitle: true } : ellipsis;
243-
if (ellipsisConfig && (ellipsisConfig.showTitle || rowType === 'header')) {
244-
if (typeof mergedChildNode === 'string' || typeof mergedChildNode === 'number') {
245-
title = mergedChildNode.toString();
246-
} else if (
247-
React.isValidElement(mergedChildNode) &&
248-
typeof mergedChildNode.props.children === 'string'
249-
) {
250-
title = mergedChildNode.props.children;
251-
}
252-
}
261+
const title = getTitleFromCellRenderChildren({
262+
rowType,
263+
ellipsis,
264+
children: childNode,
265+
});
253266

254267
const componentProps: React.TdHTMLAttributes<HTMLTableCellElement> & {
255268
ref: React.Ref<any>;

tests/FixedColumn.spec.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@ describe('Table.FixedColumn', () => {
2121

2222
const columns = [
2323
{ title: 'title1', dataIndex: 'a', key: 'a', width: 100, fixed: 'left' },
24-
{ title: 'title2', dataIndex: 'b', key: 'b', width: 100, fixed: 'left' },
24+
{
25+
title: 'title2',
26+
dataIndex: 'b',
27+
key: 'b',
28+
width: 100,
29+
fixed: 'left',
30+
ellipsis: true,
31+
render: () => <span>1111</span>,
32+
},
2533
{ title: 'title3', dataIndex: 'c', key: 'c' },
2634
{ title: 'title4', dataIndex: 'b', key: 'd' },
2735
{ title: 'title5', dataIndex: 'b', key: 'e' },

0 commit comments

Comments
 (0)