-
-
-
+
+
+
+
-
+
## API
-| 参数 | 说明 | 类型 | 默认值 |
-| --------------------- | ------------------------------------------ | -------------------------------- | ------ |
-| value | 显示文本内容 | `ReactNode \| () => ReactNode` | - |
-| title | 提示文字 | `ReactNode \| () => ReactNode` | value |
-| className | 为文本内容所在节点添加自定义样式名 | `string` | - |
-| maxWidth | 文本内容的最大宽度 | `string \| number` | - |
-| watchParentSizeChange | 监听父元素大小的变更,默认监听 window 窗口 | ` boolean` | false |
+| 参数 | 说明 | 类型 | 默认值 |
+| --------- | ----------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------- | ------ |
+| value | 显示文本内容 | `ReactNode \| () => ReactNode` | - |
+| title | 提示文字 | `ReactNode \| () => ReactNode` | value |
+| className | 为文本内容所在节点添加自定义样式名 | `string` | - |
+| dynamic | 是否开启动态测量计算宽度。true 时支持 `maxWidth`/Tooltip 透传,并自动监听容器尺寸变化重测;false 时使用 antd `Typography.Text` 做轻量省略 | `boolean` | false |
+| maxWidth | 文本内容的最大宽度(仅 `dynamic` 时生效) | `string \| number` | - |
:::info
其余参数继承自 [继承 antd4.x 的 Tooltip](https://4x.ant.design/components/tooltip-cn/#API)
diff --git a/src/ellipsisText/index.tsx b/src/ellipsisText/index.tsx
index e1f175bf2..3e1fff77d 100644
--- a/src/ellipsisText/index.tsx
+++ b/src/ellipsisText/index.tsx
@@ -1,10 +1,9 @@
-import React, { ReactNode, useCallback } from 'react';
-import { Tooltip } from 'antd';
+import React, { ReactNode } from 'react';
+import { Typography } from 'antd';
import { AbstractTooltipProps, RenderFunction } from 'antd/lib/tooltip';
-import classNames from 'classnames';
+import { omit } from 'lodash-es';
-import Resize from '../resize';
-import useEllipsisTextStyle from './useEllipsisTextStyle';
+import MeasureEllipsis from './measureEllipsis';
import { DEFAULT_MAX_WIDTH } from './utils';
import './style.scss';
@@ -29,9 +28,11 @@ export interface IEllipsisTextProps extends AbstractTooltipProps {
*/
maxWidth?: string | number;
/**
- * 监听父元素大小的改变
+ * 是否启用动态测量计算宽度。
+ * true:通过测量计算判断文本是否溢出(支持 maxWidth/Tooltip 透传),并自动监听容器尺寸变化重测;
+ * false(默认):使用 antd Typography.Text 的 ellipsis 做轻量省略。
*/
- watchParentSizeChange?: boolean;
+ dynamic?: boolean;
/**
* antd Tooltip
*/
@@ -39,37 +40,35 @@ export interface IEllipsisTextProps extends AbstractTooltipProps {
}
const EllipsisText = (props: IEllipsisTextProps) => {
- const {
- value,
- title = value,
- className,
- maxWidth,
- watchParentSizeChange = false,
- ...otherProps
- } = props;
- const [ref, isOverflow, style, onResize] = useEllipsisTextStyle(value, maxWidth);
+ const { dynamic = false } = props;
- const observerEle =
- watchParentSizeChange && ref.current?.parentElement ? ref.current?.parentElement : null;
+ if (dynamic) {
+ // dynamic 仅用于上层分流,交给测量组件前剔除,避免透传到 Tooltip
+ return