Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular-Material: display a tooltip on a form label

I would like to display a tooltip on a label. Unfortunately this does not work. Is there a simple solution ?

  <mat-form-field >
    <mat-label matTooltip="Please enter your E-Mail Address">
      E-Mail <mat-icon>help_outline</mat-icon>
    </mat-label>
    <input
      matInput
      placeholder="Enter your email"
      [formControl]="email"
     >
    <mat-error *ngIf="email.invalid">{{getErrorMessage()}}</mat-error>
  </mat-form-field>

See this Stack-Blitz Example

like image 755
Stefan Schönbächler Avatar asked Jun 05 '26 13:06

Stefan Schönbächler


1 Answers

I would use the mat-icon after your input element, as suggested in the Angular Material documentation here. It also does look a bit nicer I think, when the icon is right aligned.

<mat-form-field >
  <mat-label>E-Mail</mat-label>
  <input matInput
         placeholder="Enter your email"
         [formControl]="email">
  <mat-icon matSuffix 
            matTooltip="Please enter your E-Mail Address">
    help_outline
  </mat-icon>
  <mat-error *ngIf="email.invalid">{{getErrorMessage()}}</mat-error>
</mat-form-field>

I made a Stackblitz here.

like image 59
Fabian Küng Avatar answered Jun 07 '26 02:06

Fabian Küng



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!