Skip to content

A cross-browser javascript solution for truncating any part of a multiline text with variants of options.

License

Notifications You must be signed in to change notification settings

ipip2005/lesstextjs

Repository files navigation

image

lesstextjs

A cross-browser javascript solution for truncating any part of a multiline text that is built for variants of options.

Background

At the world of web development, one of the most common scenario which is not built-in cross-browser is called truncated-multiple-lines-of-text.

While text-overflow: ellipsis; only resolves single line truncation of the text element, and only chrome provides bulit-in solution to multiline truncation which is CSS property -webkit-line-clamp. We, as web UI developer, really need to a simple, high performant and cross-browser solution to support multiline truncation.

Demo (Vanilla JS)

https://codesandbox.io/s/yqxvx12lzv

Demo (In React/Typescript application)

Simple truncation with multiple lines

https://codesandbox.io/s/0xm2zxxk8n

Demo of Simple truncation with multiple lines

Truncate only part of the sentence

https://codesandbox.io/s/p5m07y2jzm

Demo of Truncate only part of the sentence

Use space character to separate words and do not truncate the last word. (Avoid any word to be broken up and losing meaning)

https://codesandbox.io/s/52vk27677n

Demo of Use space character to separate words and do not truncate the last word. (Avoid any word to be broken up and losing meaning)

Reserve white space for formatting

https://codesandbox.io/s/j20q95zq7v

Demo of Reserve white space for formatting

Features

  • Truncate any part of a multiline text and truncated text will end with ....

Changelog

v1.0 - Multiline Truncation, and partial truncation with '...'

TODOS

  • Truncate using requestAnimationFrame for better performance

License

LessTextJS is MIT licensed

About

A cross-browser javascript solution for truncating any part of a multiline text with variants of options.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published