[Question] How to check that only a part of the text is visible?
See original GitHub issueHi team and community. Here is my use case: our component should truncate the header text if it’s too long.
I’m trying to check this and don’t understand how to do it exactly.
What I tried: innerText
, textContent
, text
selector, isVisible
method.
Could you please suggest how to do this?
For example, if I have <h2>the really long text</h2>
, how to check that only “the really long” value is visible?
Thanks!
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to check if a specific part of a text (string) is visible after ...
The think is: I only want to show the "read more" link if the text is not fully displayed. However, the element that...
Read more >Display Logic - Qualtrics
Question : Display a question only if the respondent chose a specific answer to a ... logic to make sure the right respondents...
Read more >Add alternative text to a shape, picture, chart, SmartArt graphic ...
Right-click the object and select Edit Alt Text. Edit Alt Text option in the context menu for a picture · Select the object...
Read more >visibility - CSS: Cascading Style Sheets - MDN Web Docs
The element box is invisible (not drawn), but still affects layout as normal. Descendants of the element will be visible if they have ......
Read more >Write good Alt Text to describe images | Digital Accessibility
Only in extreme circumstances, such as when a logo is used, should you provide an image of text rather than text. If you...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
There’s no convenient/straight-forward built in API in any of the browsers, so I think a screenshot is your best approach for this case at the moment. 😢
If you’re down for some exploration, you might be able to hack something together with the
Range
API, but I haven’t thought through its limitations (nor complexity dealing with more than a very simple, minimal example):(Notice that within a single example, if you compare the
<p>
width with the selection, it would not quite give a correct answer.)This is a good instinct! However, in this specific case, I think the screenshot might be best since I don’t believe the browser exposes an API that says which part of the text has/hasn’t been elided or clipped (assuming you’re using CSS to do the overflow handling).
I’ll double check with the team to see if I’m missing something or if there is another suggestion. (cc: @pavelfeldman: if this can’t be done nicely today, without using a screenshot, this could be an non-screenshot assertion capability for layout/VRT scenarios)