Skip to content
Advertisement

show Tooltip only when the ellipsis is active

HTML:

JavaScript

CSS:

JavaScript

I want a tool-tip to be displayed dynamically purely depending on the ellipsis.But the problem is tool-tip displayed but it is also getting displayed for the data which doesn’t have ellipsis.I’m using angular-material

I have written some CSS after referring some sites

The expected behaviour is should get tool-tip only for the data which has ellipsis otherwise it should be hidden and u can see I’m using angular material.

I have seen some solutions with jquery and it doesn’t work for me. Is there a way to solve this?

Thanks in advance

Advertisement

Answer

Overflow of an element can be detected in JavaScript with this helper, using Angular ElementRef and a formula from this answer:

JavaScript

Then, in your component, use it referencing the element with a “@ViewChild” property:

JavaScript

Finally, in the template, add the identifier #hospitalName and call isHospitalNameTruncated() to customize the tooltip text:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement