by Front Factory
Clamp text to N lines or a fixed height. The toggle appears only when there is something left to read.
$ npm install @frontfactory/readmore
“Less is more.” — Robert Browning, Andrea del Sarto, 1855. Readmore takes it literally — show less, and let readers ask for more.
About 1.7 KB gzipped, with TypeScript types included.
Uses -webkit-line-clamp or max-height, so the browser does the layout work.
-webkit-line-clamp
max-height
The toggle button is created only when the text actually overflows, and removed if it stops overflowing.
aria-expanded and aria-controls are set on the toggle button and kept in sync.
aria-expanded
aria-controls