Ellipsis文本自动省略号

文本过长自动处理省略号,支持按照文本长度和最大行数两种方式截取。

引用方式:

  1. import Ellipsis from 'ant-design-pro/lib/Ellipsis';

详细使用方式请参照:独立使用 pro 组件

代码演示

NumberInfo 数据文本 - 图1

按照字符数省略

通过设置 length 属性指定文本最长长度,如果超过这个长度会自动截取。

  1. import Ellipsis from 'ant-design-pro/lib/Ellipsis';
  2. const article =
  3. 'There were injuries alleged in three cases in 2015, and a fourth incident in September, according to the safety recall report. After meeting with US regulators in October, the firm decided to issue a voluntary recall.';
  4. ReactDOM.render(
  5. <div>
  6. <Ellipsis length={100}>{article}</Ellipsis>
  7. <h4 style={{ marginTop: 24 }}>Show Tooltip</h4>
  8. <Ellipsis length={100} tooltip>
  9. {article}
  10. </Ellipsis>
  11. </div>,
  12. mountNode
  13. );

NumberInfo 数据文本 - 图2

按照行数省略

通过设置 lines 属性指定最大行数,如果超过这个行数的文本会自动截取。但是在这种模式下所有 children 将会被转换成纯文本。

并且注意在这种模式下,外容器需要有指定的宽度(或设置自身宽度)。

  1. import Ellipsis from 'ant-design-pro/lib/Ellipsis';
  2. const article = (
  3. <p>
  4. There were injuries alleged in three <a href="#cover">cases in 2015</a>, and a fourth incident
  5. in September, according to the safety recall report. After meeting with US regulators in
  6. October, the firm decided to issue a voluntary recall.
  7. </p>
  8. );
  9. ReactDOM.render(
  10. <div style={{ width: 200 }}>
  11. <Ellipsis tooltip lines={3}>
  12. {article}
  13. </Ellipsis>
  14. </div>,
  15. mountNode
  16. );

API

参数说明类型默认值
tooltip移动到文本展示完整内容的提示boolean-
length在按照长度截取下的文本最大字符数,超过则截取省略number-
lines在按照行数截取下最大的行数,超过则截取省略number1
fullWidthRecognition是否将全角字符的长度视为 2 来计算字符串长度boolean-