Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Material button remove autofocus

Tags:

I have the following button

<td mat-cell *matCellDef="let element">   <button mat-icon-button type="button" (click)="downloadStuff(element)">     <mat-icon mat-icon matTooltip="{{element.someId}}">picture_as_pdf</mat-icon>   </button> </td> 

All good but I noticed the little bugger gets outlined by default:

enter image description here

Ok.... CSS lets me remove the annoying outline withe the following:

button:focus {     outline: none; } 

But then.. I still get this annoying default background focus:

enter image description here

I've tried a few overlay and background-related things in CSS and none of these seemed to address the issue. How do I remove this default background? And why does it behave like this by deafault???

See the selected item in dev tools. enter image description here

like image 755
tom33pr Avatar asked Dec 12 '18 10:12

tom33pr


People also ask

How do I remove autofocus from button?

If you want to remove the focus around a button, you can use the CSS outline property. You need to set the “none” value of the outline property.


2 Answers

In my case the real problem was the button structure. Angular Material builds various sub components and the last one is a 'div' with css class mat-button-focus-overlay:

My solution is simply. In style.css add or overwrite the mat-button-focus-overlay:

.mat-button-focus-overlay {     background-color: transparent!important; } 
like image 125
Pablo M. Avatar answered Oct 06 '22 06:10

Pablo M.


After clicking or touching on a Material Design button it stays focused ---> to resolve this, you need to add the following code: onclick="this.blur()"

<button mat-raised-button  onclick="this.blur()" (click)="onEdit()">Edit</button> 

or in your case

<td mat-cell *matCellDef="let element">     <button mat-icon-button type="button" onclick="this.blur()" (click)="downloadStuff(element)">         <mat-icon mat-icon matTooltip="{{element.someId}}">picture_as_pdf</mat-icon>     </button> </td> 
like image 34
Botond Avatar answered Oct 06 '22 07:10

Botond