My Goal
I aim to develop a method for determining the amount of a string visible before it gets cut off.
Motivation
In my project, there is a collection of items that can be chosen. A panel presents a concatenated string of the selected item names separated by commas. If the string exceeds a certain length, it should be shortened with a +{number} indicating additional hidden selections.
Illustrative Example
https://stackblitz.com/edit/angular-ivy-cbyemy
The provided StackBlitz contains a basic demonstration of this scenario.
Current panel title:
an item, another item, som... +6
Desired outcome:
an item, another item, som... +3
Attempts So Far
- My efforts involved using element.innerHTML and element.innerText to extract the displayed portion of the string, but they only return the full un-truncated text.