Text Wrapping
Text Wrapping
Section titled “Text Wrapping”By default, cell text is rendered on a single line and truncated with an ellipsis (…) when it overflows. Enable wrapText on a column to wrap long text into multiple lines within the cell.
Configuration
Section titled “Configuration”Set wrapText: true on a ColumnDef:
const columns: ColumnDef[] = [ { key: 'id', title: 'ID', width: 60 }, { key: 'notes', title: 'Notes', width: 250, wrapText: true }, { key: 'description', title: 'Description', width: 300, wrapText: true },];Wrapping Behavior
Section titled “Wrapping Behavior”Wrapped Text (wrapText: true)
Section titled “Wrapped Text (wrapText: true)”- Text is split on explicit
\nnewlines - Each paragraph is broken into words by whitespace
- Words are placed greedily until the line exceeds the available width
- If a single word is wider than the column, it is split character-by-character
- Lines are rendered vertically centered within the cell
Available width: 200pxText: "This is a long sentence that will wrap"
Line 1: "This is a long"Line 2: "sentence that will"Line 3: "wrap"Non-Wrapped Text (Default)
Section titled “Non-Wrapped Text (Default)”When wrapText is not set:
- Text is measured against available cell width
- If it overflows, a binary search finds the longest prefix that fits
- An ellipsis (
…) is appended - Result:
"This is a long sen…"
Text Alignment
Section titled “Text Alignment”Both wrapped and non-wrapped text respect horizontal alignment. Alignment is determined by the cell type renderer. Each wrapped line is aligned independently.
Auto Row Height
Section titled “Auto Row Height”Wrapped text only affects row height when autoRowHeight is enabled. Without it, wrapped text that exceeds the fixed row height is clipped.
<Spreadsheet columns={columns} data={data} autoRowHeight={true}/>With auto row height, the engine measures the height of wrapped content and expands the row. The height formula is:
lineCount × emHeight × 1.2 + cellPaddingWhere emHeight is measured from the font’s actualBoundingBoxAscent + actualBoundingBoxDescent.
Performance
Section titled “Performance”Text measurement uses a TextMeasureCache with three internal caches:
| Cache | Purpose | Capacity |
|---|---|---|
| Width cache | measureText() results | LRU, 10K entries |
| Wrap cache | getWrappedLines() line arrays | Keyed by font + text + maxWidth |
| Height cache | measureEmHeight() font metrics | Keyed by font string |
Cache keys include font information, so theme or style changes produce fresh measurements.
Column resize on a wrapText column invalidates auto row height measurements for all rows, since available width changes affect line breaking.
See Also
Section titled “See Also”- Auto Row Height — automatic row sizing based on wrapped content
- Column Stretch — auto-filling container width affects available wrap width
- Column & Row Resize — manual column resize triggers re-wrap