Seed Bible extension API (v1.18.0) / seed-bible/components / ExpandableText
Function: ExpandableText()
function ExpandableText(props: {
children: string;
className?: string;
lines?: number;
readLessLabel: string;
readMoreLabel: string;
}): Element | null;Shows text with a "Read more" / "Read less" control when it does not fit. Collapsed, it reads as one line of prose — text... Read more — with the ellipsis and the control on the same baseline as the text. Expanded, the full text is shown with its line breaks preserved.
Whether it fits is measured, not estimated: the collapsed line is clipped by the browser and scrollWidth is compared against clientWidth on that same element — two real measurements of one element, so nothing has to be assumed about the font.
An earlier version instead built the budget by hand: one line of getComputedStyle().lineHeight, which is the keyword "normal" here, so it fell back to fontSize * 1.2. That guess lands inside a pixel of a real line box, and which side it lands on depends on the font's own metrics. Measured at this font size in Chromium: 1.15 for the default sans stack, so the guess held; 1.39 for a CJK fallback and 1.62 for a Thai one, where a single short line measured over the budget and every description, however short, was given a "Read more" that expanded to nothing. --sb-font-family is themeable and system-ui resolves per platform, so the guess was never one the component could make.
Labels are passed in already-translated so this stays i18n-agnostic (same pattern as SkeletonContainer).
Parameters
| Parameter | Type | Description |
|---|---|---|
props | { children: string; className?: string; lines?: number; readLessLabel: string; readMoreLabel: string; } | - |
props.children | string | - |
props.className? | string | - |
props.lines? | number | How many lines to show before collapsing. Defaults to 1. Above 1, the text wraps within the budget rather than showing only its first line. |
props.readLessLabel | string | Already-translated "Read less" label. |
props.readMoreLabel | string | Already-translated "Read more" label. |
Returns
Element | null