Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show mdTooltip until clicked, hide when clicked again

I'm trying to disable the mouse-hover effect and trigger mdTooltip on click and disable it on clicking again. Is it possible to do that? I thought the .toogle() method would be the right tool for that unfortunately it works the opposite way.

<div style="text-align: center;">
   <span matTooltip="Tooltip!" #tooltip="matTooltip" (click)="tooltip.toggle()">Test</span> 
</div>
like image 751
Paul Pinter Avatar asked Oct 06 '17 09:10

Paul Pinter


2 Answers

IMO, A better solution is using matTooltipDisabled

set it as false right before you call show and set it as true when you call hide

So you don't trigger extra change detection because of listening mouse events. (In this case, we can save 2, mouseenter and mouseleave )

like image 200
maxisam Avatar answered Oct 25 '22 20:10

maxisam


You should try using event.stopImmediatePropagation();

<span matTooltip="Tooltip!" 
  (mouseenter)="$event.stopImmediatePropagation()" 
  (mouseleave)="$event.stopImmediatePropagation()"
  #tooltip="matTooltip" (click)="tooltip.toggle()">Test</span> 

Plunker Example

like image 40
yurzui Avatar answered Oct 25 '22 19:10

yurzui