-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Newline handling #28
Comments
obecker
added a commit
to obecker/nanoclamp
that referenced
this issue
Mar 24, 2024
obecker
added a commit
to obecker/nanoclamp
that referenced
this issue
Mar 24, 2024
obecker
added a commit
to obecker/nanoclamp
that referenced
this issue
Mar 24, 2024
See #29 |
obecker
added a commit
to obecker/nanoclamp
that referenced
this issue
Mar 24, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If the text to be clamped contains line breaks, then they will be preserved in the created element (by adding
<br>
elements). This should not happen. The display of line breaks should only be controlled by the CSSwhite-space
property.Solution: the text should be inserted by using
textContent
instead ofinnerText
.See https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent
Moreover, if line breaks are preserved and the last displayed line is short enough for the containing element, it is still shortened before adding the ellipsis.
Example:
Using
<NanoClamp text={text} lines={2} />
for this text (in a wide enough div) results inI would expect that the word
multiple
is not shortened (since it's not necessary), so the result should rather beSolution: in the loop that finds the proper index in the text always append the ellipsis before checking the height of the element.
The text was updated successfully, but these errors were encountered: