DEV Community

Dominic Myers
Dominic Myers

Posted on • Originally published at drmsite.blogspot.com on

wc-trim-middle

By Marie Vander Meiren via scopio

I've lost track of the number of times I've needed to truncate text online, and I've tried all sorts of mechanisms, so when I came across Christian Heilmann's trimMiddle() function, I was happy as Larry.

So happy that I just had to convert it into a web component. After reading about how problematic people are finding styling web components from outside, I also decided to create it without a shadow DOM, and I'm pleased with the result.

There's a functional demo. However, I found it very frustrating to make it accept dynamic changes to the inner text. Have a play and see if it fits your requirements.

Top comments (0)