Expandable text
Long text clamped to a fixed line count with a soft bottom fade and a toggle shown only on overflow.
import { ExpandableText } from '@uthereal/ui/expandable-text'Expandable text playground
Release 2.4 reduces cold-start latency across regional workers by 38% and adds incremental snapshot verification for long-running sync jobs. Teams running multi-region replicas now get deterministic failover with automatic read-after-write guarantees and zero manual intervention.
Before updating shared staging environments, review the updated retention defaults and verify that custom webhook consumers tolerate out-of-order replay markers during the initial catch-up window.
Overview
ExpandableText clamps long copy to a fixed number of lines with a soft fade mask over the final line. The component renders only the clamped text and the toggle button, with no outer card or container chrome. It fits descriptions, release notes, user bios, and summaries that should stay compact until a reader opens them.
Use scroll area when content must stay inside a fixed-height scrollable region. Use accordion when several titled sections expand and collapse independently.
Usage
import { ExpandableText } from '@uthereal/ui/expandable-text'
export function ReleaseSummary() {
return (
<ExpandableText lines={3}>
<p>
Release 2.4 reduces cold-start latency across regional workers and adds
incremental snapshot verification for long-running sync jobs.
</p>
<p>
Review the <a href="#changelog">full migration notes</a> before updating
shared staging environments.
</p>
</ExpandableText>
)
}Pass children in React when the copy includes paragraphs or inline links. Pass text for plain-text or serializable agent configs; children takes precedence when both are supplied. Pass expanded and onExpandedChange to control the state from the host.
Examples
Clamping, custom labels, and overflow detection
Set lines to control the collapsed height, customize moreLabel and lessLabel for the toggle, or pass defaultExpanded to start open. When the text fits inside the line limit, the toggle hides automatically.
Migration notes for workspace administrators: existing API tokens continue to work without rotation, while newly issued service credentials default to scoped read-only permissions.
Review the updated webhook delivery retries and audit retention defaults before promoting changes from staging to production.
Clamping and focus behavior
| Mechanism | Behavior |
|---|---|
| Overflow probe | A hidden zero-width probe measures lines * 1lh via ResizeObserver alongside the content wrapper. The toggle renders only when content height exceeds the probe height, and updates automatically when container width, font size, or content changes. |
| Focus auto-expand | When a link or control inside the clamped region receives keyboard focus below the visible edge, the text expands automatically so focus is never clipped. |
| Scroll recovery | Collapsing the text after scrolling past its top edge scrolls the start of the component back into view (smooth when motion is enabled, auto otherwise). |
API reference
These serializable arguments and defaults come directly from the component schema.
| Argument | Type / default | Description |
|---|---|---|
text | string— | Plain-text body copy for serializable configs. React callers pass children when paragraphs or inline links are needed. |
lines | integerDefault: 3 | Visible line count while collapsed, measured in the text line height. |
defaultExpanded | booleanDefault: false | Initial expanded state. Later edits do not reset a mounted instance; in a composition, stored host state wins. |
moreLabel | stringDefault: "Read more" | Toggle label while collapsed. |
lessLabel | stringDefault: "Show less" | Toggle label while expanded. |
recipe | studio | softDefault: "studio" | Visual treatment. Both recipes use the same behavior. |
theme | ExpandableTextTheme— | Color mode, accent, and tokens for text hierarchy, typography, focus ring, and toggle hit height. |
motion | none | subtle | expressiveDefault: "subtle" | Animation preset for height, fade mask, chevron turn, and label crossfade. Preset none is immediate (0ms); system reduced motion expands and collapses immediately with a plain opacity label swap. |
motionOptions | ExpandableTextMotionOptions— | Base expand and collapse durations in milliseconds; merges over the motion preset. |
dir | ltr | rtl— | Reading direction. Omit to inherit the page direction. |
React integration
| Prop | Purpose |
|---|---|
children | Rich body content (strings, paragraphs, inline links). Overrides text. |
expanded | Controlled open state. |
onExpandedChange(expanded) | Called whenever the expanded state changes, in both controlled and uncontrolled modes. |
ref | Ref forwarded to the root <div>. |
preset | Application defaults overridden by explicit instance props. |
tokens | CSS custom properties (--ui-*) applied after the typed theme. |
className, style | Applied to the root <div>. |
| Native attributes | Standard div attributes such as id, data-*, and onFocusCapture. |
Keyboard & accessibility
| Key | Interaction |
|---|---|
Tab / Shift+Tab | Moves focus to interactive elements inside the text and to the toggle button. Focusing an element hidden below the clamp expands the text. |
Enter / Space | Activates the toggle button to expand or collapse the text. |
Full text stays mounted in the DOM and accessibility tree while clamped so screen readers and page search still read it. The toggle button sets aria-expanded and links to the content container with aria-controls. Both toggle labels occupy one CSS grid cell so button width stays stable; the inactive label carries aria-hidden="true". Logical CSS properties adapt layout and toggle alignment automatically in dir="rtl". Under forced-colors: active, the toggle and chevron inherit ButtonText and focus outlines use Highlight.
Motion and theming
One shared progress value drives container height, fade mask opacity, and the 180-degree chevron rotation in lockstep on Arc's enter ease (cubic-bezier(0.16, 1, 0.3, 1)). Opening uses a 480ms base duration plus up to 120ms scaled by travel distance; closing uses 240ms plus up to 120ms. Toggling mid-flight reverses smoothly from the current height instead of restarting.
| Motion setting | Height, fade, and chevron | Toggle labels and press feedback |
|---|---|---|
subtle (default) | Distance-scaled enter ease (480ms open / 240ms close base). | 240ms opacity and 2px blur crossfade with 4px vertical drift; 0.97 active press scale. |
expressive | 1.2x base durations (576ms open / 288ms close base) on the same enter ease. | Matches the longer travel duration for label drift. |
prefers-reduced-motion: reduce | Expands and collapses immediately (0ms); scroll recovery uses auto. | Plain 120ms opacity crossfade with no blur, no vertical drift, and no press scale. |
none | Expands and collapses immediately (0ms); scroll recovery uses auto. | Immediate 0ms label swap with no blur, no drift, and no press scale. |
theme accepts mode, accent, and tokens for foreground, textSecondary, mutedForeground, focusRing, fontFamily, fontSize, fontWeight, and toggleMinHeight (default 28px, emitted as --ui-expandable-text-toggle-min-height). An application-wide UtherealProvider supplies defaults.
Composition
In an agent composition, ExpandableText is a leaf element. Supply body copy through text. The host persists expanded at /components/instance-<id>/expanded across edits, overriding defaultExpanded after mount. See Building with agents.
{
"type": "ExpandableText",
"props": {
"text": "Release 2.4 reduces cold-start latency across regional workers and adds incremental snapshot verification for long-running sync jobs. Review the migration notes before updating shared staging environments.",
"lines": 3,
"moreLabel": "Read more",
"lessLabel": "Show less"
}
}