0

I want to show a tooltip when i click an icon, not by hovering on it.

<a title="Tooltip">
    <i class="fa fa-info-circle"></i>
</a>

I also want to be able to customize to the tooltip with some classes like:

<div class="a-tooltip a-tooltip--top-right">
  This is my tooltip text!
</div>

My try:

<a (click)="tooltip.toggle()"
   #tooltip="matTooltip"
   matTooltip="test"
   aria-label="Button that displays a tooltip when focused or hovered over">
   <i class="fa fa-info-circle"></i>
</a>

This does however not show a tooltip on clicking. In app.module.ts i have:

import { MatTooltipModule } from '@angular/material';

@NgModule({
    declarations: [
        ...
    ],
    imports: [
        MatTooltipModule 
    ]
})
2
  • 1
    What did you try so far? Where are you failing? Commented Mar 7, 2019 at 10:38
  • @emkay see update. Commented Mar 7, 2019 at 11:49

1 Answer 1

4

By default mat-tooltip is designed for mouse hover. If, you want to disable that use the following code :

<span matTooltip="Tooltip!" 
  (mouseenter)="$event.stopImmediatePropagation()" 
  (mouseleave)="$event.stopImmediatePropagation()"
  #tooltip="matTooltip" (click)="tooltip.toggle()">Test</span> 
Sign up to request clarification or add additional context in comments.

2 Comments

With this, I can make an Icon clickable. However, the tooltip is not show near the clicked element, but a mat-tooltip-component is placed at the bottom of my page, below the footer...
Please provide an example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.