Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable Angular Material Expansion Panel animations?

How to disable the animation when you click on the expansion panel? I tried this:

::ng-deep .mat-expansion-panel-header {
    transition: none !important; 
}

and also this:

::ng-deep .mat-expansion-panel-body {
    transition: none !important; 
}

But none are working for me, animation is still here.

<mat-expansion-panel>
  <mat-expansion-panel-header>
    Settings
  </mat-expansion-panel-header>
    Some content
<mat-expansion-panel>
like image 821
Chris K Avatar asked Jul 18 '18 09:07

Chris K


1 Answers

Update 2020-10-16:

[@.disabled]=true won't work any more - based on response from Angular issue tracker (https://github.com/angular/components/issues/20768):

...we changed the expansion panel from using Angular animations to using plain CSS animations...

I think the proper approach now would be to add the following styles to your global styles.css files (or scope them as needed):

mat-expansion-panel,
mat-expansion-panel * {
  transition: none !important;
}

Like here (based on the sample by Benjamin): https://stackblitz.com/edit/mat-expansion-panel-10-lgagfp?file=src/styles.scss

Old answer:

You can add

[@.disabled]="true"

binding to your <mat-expansion-panel> element to disable animations for the given panel.

Read more here: https://angular.io/api/animations/trigger#disabling-animations

like image 166
user1503948 Avatar answered Sep 27 '22 03:09

user1503948