Truncated Text

Text that ends with an ellipsis when it doesn't fit, and shows the full text in a tooltip only while it is cut off.

Single line

By default the text stays on one line. Hover or focus a prompt that is cut off to read all of it; prompts that fit show no tooltip. Overflow is measured when the pointer enters or the text gets focus, so there is no layout work until someone wants to read it.

Set typography and color with className. Truncated Text needs a TooltipProvider above it, which apps already render at the root.

Best CRM for startups
Which project management tools integrate with Slack and Google Drive for remote teams?
Top running shoes for flat feet
How do enterprise security teams compare SSO providers for compliance with SOC 2 and HIPAA?

In a flex row

In a flex row, give the text min-w-0 flex-1 so it can shrink, and shrink-0 to the icons and metadata that should keep their size. Any flex parent between the row and the text also needs min-w-0.

Q3 visibility report for Acme across ChatGPT, Perplexity and Gemini
Report
Competitor citations
Sheet
Launch brief for the spring product line and answer engine strategy
Document

Multiple lines

lines clamps the text to that many lines before the ellipsis. The tooltip still appears only when text is hidden.

Visibility
Acme's share of voice in ChatGPT rose 12% after its pricing page was cited in 40 new answers about CRM tools.

Custom tooltip

The tooltip shows the children by default. Pass tooltip when the children are rich content and the tooltip should be plain text, and tooltipSide or tooltipSideOffset to move it. When a parent owns the tooltip, disableTooltip turns it off; the ref still points at the truncating element so the parent can measure it.

Maya Chen added 3 citations from nytimes.com to the brand report
2h

Properties

childrenRequired
React.ReactNode

The text to show. Also the tooltip content unless tooltip is set

tooltip
React.ReactNode

Tooltip content to show instead of children

lines
number

Lines to show before the ellipsis

Default: 1

disableTooltip
boolean

Turns off the tooltip when a parent owns it

tooltipSide
'top''right''bottom''left'

Side the tooltip opens toward

Default: top

tooltipSideOffset
number

Distance in pixels between the tooltip and the text. Defaults to the tooltip's own offset

className
string

Additional CSS classes for the truncating element, such as typography and color

ref
React.Ref<HTMLDivElement>

Ref to the truncating element