fix: table ellipsis title not work, close #5755

pull/5702/merge
tangjinzhou 2022-06-30 10:36:33 +08:00
parent d94fe1c0b2
commit f672f873dc
1 changed files with 22 additions and 5 deletions

View File

@ -1,7 +1,12 @@
import classNames from '../../_util/classNames';
import { flattenChildren, isValidElement, parseStyleText } from '../../_util/props-util';
import type { CSSProperties } from 'vue';
import { computed, defineComponent, isVNode, renderSlot } from 'vue';
import {
filterEmpty,
flattenChildren,
isValidElement,
parseStyleText,
} from '../../_util/props-util';
import type { CSSProperties, VNodeArrayChildren } from 'vue';
import { Text, computed, defineComponent, isVNode, renderSlot } from 'vue';
import type {
DataIndex,
@ -145,6 +150,18 @@ export default defineComponent<CellProps>({
additionalProps?.onMouseleave?.(event);
};
const getTitle = (vnodes: VNodeArrayChildren) => {
const vnode = filterEmpty(vnodes)[0];
if (isVNode(vnode)) {
if (vnode.type === Text) {
return vnode.children;
} else {
return Array.isArray(vnode.children) ? getTitle(vnode.children) : undefined;
}
} else {
return vnode;
}
};
return () => {
const {
prefixCls,
@ -298,8 +315,8 @@ export default defineComponent<CellProps>({
if (ellipsisConfig && (ellipsisConfig.showTitle || rowType === 'header')) {
if (typeof childNode === 'string' || typeof childNode === 'number') {
title = childNode.toString();
} else if (isVNode(childNode) && typeof childNode.children === 'string') {
title = childNode.children;
} else if (isVNode(childNode)) {
title = getTitle([childNode]);
}
}