Text Edit

This feature is still experimental. “Experimental” means this is an early implementation subject to drastic and breaking changes.

Text is a core component that renders text in the library, using the library’s typography system.

Usage Usage

Text can be used to render any text-content, like an HTML p or span.

import { __experimentalText as Text } from '@wordpress/components';

function Example() {
    return <Text>Code is Poetry</Text>;
}

Top ↑

Props Props

Top ↑

adjustLineHeightForInnerControls adjustLineHeightForInnerControls

Type: boolean,"large","medium","small","xSmall"

Automatically calculate the appropriate line-height value for contents that render text and Control elements (e.g. TextInput).

import { __experimentalText as Text, TextInput } from '@wordpress/components';

function Example() {
    return (
        <Text adjustLineHeightForInnerControls>
            Lorem ipsum dolor sit amet, consectetur
            <TextInput value="adipiscing elit..." />
        </Text>
    );
}

Top ↑

align align

Type: CSSProperties['textAlign']

Adjusts the text alignment.

import { __experimentalText as Text } from '@wordpress/components';

function Example() {
    return (
        <Text align="center" isBlock>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit...
        </Text>
    );
}

Top ↑

color color

Type: CSSProperties['color']

Adjusts the text color.

Top ↑

display display

Type: CSSProperties['display']

Adjusts the CSS display.

Top ↑

ellipsis ellipsis

Type: string

The ellipsis string when truncate is set.

Top ↑

ellipsizeMode ellipsizeMode

Type: "auto","head","tail","middle"

Determines where to truncate. For example, we can truncate text right in the middle. To do this, we need to set ellipsizeMode to middle and a text limit.

  • auto: Trims content at the end automatically without a limit.
  • head: Trims content at the beginning. Requires a limit.
  • middle: Trims content in the middle. Requires a limit.
  • tail: Trims content at the end. Requires a limit.

Top ↑

highlightCaseSensitive highlightCaseSensitive

Type: boolean

Escape characters in highlightWords which are meaningful in regular expressions.

Top ↑

highlightEscape highlightEscape

Type: boolean

Determines if highlightWords should be case sensitive.

Top ↑

highlightSanitize highlightSanitize

Type: boolean

Array of search words. String search terms are automatically cast to RegExps unless highlightEscape is true.

Top ↑

highlightWords highlightWords

Type: any[]

Letters or words within Text can be highlighted using highlightWords.

import { __experimentalText as Text } from '@wordpress/components';

function Example() {
    return (
        <Text highlightWords={ [ 'pi' ] }>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc ex
            neque, vulputate a diam et, luctus convallis lacus. Vestibulum ac
            mollis mi. Morbi id elementum massa. Suspendisse interdum auctor
            ligula eget cursus. In fermentum ultricies mauris, pharetra
            fermentum erat pellentesque id.
        </Text>
    );
}

Top ↑

isBlock isBlock

Type: boolean

Sets Text to have display: block.

Top ↑

isDestructive isDestructive

Type: boolean

Renders a destructive color.

Top ↑

limit limit

Type: number

Determines the max characters when truncate is set.

Top ↑

lineHeight lineHeight

Type: CSSProperties['lineHeight']

Adjusts all text line-height based on the typography system.

Top ↑

numberOfLines numberOfLines

Type: number

Clamps the text content to the specifiec numberOfLines, adding the ellipsis at the end.

Top ↑

optimizeReadabilityFor optimizeReadabilityFor

Type: CSSProperties['color']

The Text color can be adapted to a background color for optimal readability. optimizeReadabilityFor can accept CSS variables, in addition to standard CSS color values (e.g. Hex, RGB, HSL, etc…).

import { __experimentalText as Text, View } from '@wordpress/components';

function Example() {
    const backgroundColor = 'blue';

    return (
        <View css={ { backgroundColor } }>
            <Text optimizeReadabilityFor={ backgroundColor }>
                Lorem ipsum dolor sit amet, consectetur adipiscing elit.
            </Text>
        </View>
    );
}

Top ↑

size size

Type: CSSProperties['fontSize'],TextSize

Adjusts text size based on the typography system. Text can render a wide range of font sizes, which are automatically calculated and adapted to the typography system. The size value can be a system preset, a number, or a custom unit value (string) such as 30em.

import { __experimentalText as Text } from '@wordpress/components';

function Example() {
    return <Text size="largeTitle">Code is Poetry</Text>;
}

Top ↑

truncate truncate

Type: boolean

Enables text truncation. When truncate is set,we are able to truncate the long text in a variety of ways.

import { __experimentalText as Text } from '@wordpress/components';

function Example() {
    return (
        <Text truncate>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc ex
            neque, vulputate a diam et, luctus convallis lacus. Vestibulum ac
            mollis mi. Morbi id elementum massa. Suspendisse interdum auctor
            ligula eget cursus. In fermentum ultricies mauris, pharetra
            fermentum erat pellentesque id.
        </Text>
    );
}

Top ↑

upperCase upperCase

Type: boolean

Uppercases the text content.

Top ↑

variant variant

Type: "muted"

Adjusts style variation of the text.

import { __experimentalText as Text } from '@wordpress/components';

function Example() {
    return <Text variant="muted">Code is Poetry</Text>;
}

Top ↑

weight weight

Type: CSSProperties['fontWeight'],TextWeight

Adjusts font-weight of the text.