frontend/src/components/ui/Rocket/TruncatingText/TruncatingText.spec.md
TruncatingText renders a string with CSS ellipsis. When the rendered text actually overflows its container, it sets a title attribute on the element so the browser's native tooltip reveals the full string on hover. When the text fits, no title is attached — short values get no tooltip noise.
Use it anywhere text may or may not fit its container: row labels in dropdowns, selected values in Select triggers, table cells, sidebar entries.
| Prop | Type | Default | Notes |
|---|---|---|---|
| text | node | — | String content. Wins over children when both are passed. |
| children | node | — | Alternative way to pass content. |
| className | string | — | Forwarded to the rendered <span>. |
| title | string | — | Manual override. When set, replaces the auto-detected title. Use this if children is JSX and you want to provide the plain-text equivalent for the tooltip. |
// Basic — auto-detects overflow on the string
<TruncatingText text={query.name} />
// Inside a flex row — parent needs min-w-0 to allow shrinking
<div className="tw-flex tw-min-w-0 tw-items-center tw-gap-2">
<Icon />
<TruncatingText text={longLabel} className="tw-flex-1" />
</div>
// Wrapping a component that renders text from context (Radix SelectValue)
<TruncatingText title={query.name}>
<SelectValue />
</TruncatingText>
<span> with tw-block tw-truncate (applies overflow: hidden; text-overflow: ellipsis; white-space: nowrap).title={fullText} only when scrollWidth - clientWidth > 0.5. Hover triggers the OS tooltip.ResizeObserver on the span itself.MutationObserver on the subtree (childList + characterData). Required so wrappers like Radix SelectValue / ComboboxValue, which render selected text from context (not from props), trigger re-measurement when the selection changes.title attribute is only auto-set for string content. If children is a React element (e.g. <SelectValue />), the auto-detection still measures correctly but cannot extract a string for the title — pass it explicitly via the title prop.title is undefined, set after mount via useLayoutEffect. First paint is the bare ellipsis; the title appears once measurement runs.Considered wrapping in our Rocket Tooltip (Radix-based) so the hover bubble matches design-system styling. Rejected for these reasons:
<TooltipProvider> ancestor, easy to forget.The native title attribute eliminates all of the above. The DOM shape never changes; only the attribute toggles. The styled Rocket Tooltip remains the right choice for deliberate informational tooltips (help text, descriptions) — different job, different primitive.
min-w-0. Otherwise the element grows to its content's intrinsic width and never clips. CSS convention, not a TruncatingText quirk.