Skip to content

useSplitLines

Measures how text wraps into lines so each line can animate on its own.

For text that is revealed or styled line by line, where the lines depend on the width. Render words into a hidden node that wraps exactly as the visible text does (the same width, font and padding) and attach measureRef to it; lines then holds the words of each row. It is null until the first measurement in the browser, so render the plain text until then, and it is measured again when the container resizes and when the fonts have loaded. @khaeli/text-reveal is built on it.

Lines as the container resizes

Every task in the March release has an owner, a due date and a reviewer. The notes go out on Wednesday morning.

Installation

npx shadcn@latest add @khaeli/use-split-lines

Installs with

Nothing else. This item needs no other Registry item and no npm package.

Accessible name

  • Hide the measuring node with aria-hidden: it repeats the text. Keep the lines inside one paragraph, so a screen reader reads a sentence and not a list of fragments.

Registry JSON

The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/use-split-lines.json