Components: Mat Tab breaks animation state by setting to void

Created on 2 Jan 2019  路  5Comments  路  Source: angular/components

What is the expected behavior?

When Child components of mat-tab have angular animation, the state of the animation should not be affected by switching tabs.

What is the current behavior?

When child components of mat-tab have angular animation, switching tabs will cause the state of the animation to be set to void, thus breaking the UI of the child components.

What are the steps to reproduce?

https://stackblitz.com/edit/angular-material2-issue-d8fjgg
In the demo, we have 3 states, expanded state will expand the div height to 300px, collapsed state will collapse the div height to 30px, and void state will set the div height to 150px.
Switching tabs will always reset the div height to 150px, regardless of what the actual current state is.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Angular 7.0.1

P3 materiatabs

Most helpful comment

There's a better way that solves this problem, and it's to style the void state. You can read more about it here:

state("void", style({
display: "none",
height: "0px",
})),

All 5 comments

I'm seeing this same behavior with mat-tab.

MacOS Mojave 10.14.4
Safari 12.1 (14607.1.40.1.4) and Google Chrome 73.0.3683.86 (Official Build) (64-bit)
Angular CLI: 7.3.3
Node: 8.11.3
OS: darwin x64
Angular: 7.2.6

Package Version

@angular-devkit/architect 0.13.3
@angular-devkit/build-angular 0.13.3
@angular-devkit/build-optimizer 0.13.3
@angular-devkit/build-webpack 0.13.3
@angular-devkit/core 7.3.3
@angular-devkit/schematics 7.3.3
@angular/animations 7.2.7
@angular/cdk 7.3.3
@angular/cli 7.3.3
@angular/material 7.3.3
@ngtools/webpack 7.3.3
@schematics/angular 7.3.3
@schematics/update 0.13.3
rxjs 6.3.3
typescript 3.2.4
webpack 4.29.0

I faced this issue too.
As a temporary solution, I used directive [matTabContent] so components inside tabs now reload every time and animation states now pristine and fine.

From docs:

<mat-tab-group>
  <mat-tab label="First">
    <ng-template matTabContent>
      Content 1 - Loaded: {{getTimeLoaded(1) | date:'medium'}}
    </ng-template>
  </mat-tab>
  <mat-tab label="Second">
    <ng-template matTabContent>
      Content 2 - Loaded: {{getTimeLoaded(2) | date:'medium'}}
    </ng-template>
  </mat-tab>
  <mat-tab label="Third">
    <ng-template matTabContent>
      Content 3 - Loaded: {{getTimeLoaded(3) | date:'medium'}}
    </ng-template>
  </mat-tab>
</mat-tab-group>

Still happens with 8.1.4.

Don't want to use @ghost solution since in my case it is not visually appealing.

I'm going to test if a pure CSS animation do work in this case.

Well, with simple CSS animations worked like a charm, although I prefer to have them with Angular animations :/

There's a better way that solves this problem, and it's to style the void state. You can read more about it here:

state("void", style({
display: "none",
height: "0px",
})),

Was this page helpful?
0 / 5 - 0 ratings

Related issues

constantinlucian picture constantinlucian  路  3Comments

jelbourn picture jelbourn  路  3Comments

xtianus79 picture xtianus79  路  3Comments

theunreal picture theunreal  路  3Comments

crutchcorn picture crutchcorn  路  3Comments