Truncate is a typography primitive that trims text content.
For almost all cases, it is recommended that Text, Heading, or
Subheading is used to render text content. However,Truncate is
available for custom implementations.
import { __experimentalTruncate as Truncate } from '@wordpress/components';
LinksPermalink to this section
PropsPermalink to this section
| Name | Default | Description |
|---|---|---|
ellipsis | '…' |
The ellipsis string when truncating the text by the |
ellipsizeMode | 'auto' |
Determines where to truncate. For example, we can truncate text right in
the middle. To do this, we need to set
|
limit | 0 |
Determines the max number of characters to be displayed before the rest
of the text gets truncated. Requires |
numberOfLines | 0 |
Clamps the text content to the specified |
children Required |
The children elements. Note: text truncation will be attempted only if the | |
as |
The HTML element or React component to render the component as. |
ExamplesPermalink to this section
DefaultPermalink to this section
const Default = () => {
return <Truncate numberOfLines={2}>{defaultText}</Truncate>;
};
Truncate by character countPermalink to this section
const CharacterCount = () => {
return <Truncate limit={23} ellipsizeMode="tail" ellipsis="[---]">{defaultText}</Truncate>;
};