Skip to content

UI: Add truncation support to Text component #77391

@aduth

Description

@aduth

What problem does this address?

The @wordpress/ui Text component doesn't provide any built-in support for truncation behavior, requiring developers to implement this themselves (e.g. #77012, #77372). From a design system perspective, we should seek to ensure consistency and provide baseline support for how content is truncated.

What is your proposed solution?

Add props for:

  • Enabling truncation (e.g. truncate, a boolean)
  • Controlling number of lines (e.g. numberOfLines or lineClamp, a number)

In adding support, we should also remove existing workarounds, like those in the pull requests referenced above (#77012, #77372).

We should be careful to consider scope creep and what's minimally necessary to provide baseline functionality and consistency for such a low-level component.

For background, the @wordpress/components Text component composes options from the Truncate component, which provides a lot of control over specific truncation behavior (ellipsis string, trimming behavior, character limit, line limit). Many of these are rarely (or never, in the case of ellipsis) used, and arguably could be counter-productive to the design system's intent of providing consistency.

truncate and numberOfLines are the most regularly used options today. Other component libraries like Chakra UI's Text component provide exactly this amount of customization as well.

Open question: Is this a good enough combination of (a) being commonly used, (b) being difficult to implement without, and (c) prone to being implemented inconsistency, in order to warrant the maintenance cost and scope inflation to implement baseline support?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions