[Tabs] Add ability to disable animations
Bug, feature request, or proposal:
Feature request
What is the expected behavior?
I would like to disable the slide-in animation
What is the current behavior?
The slide-in animation cannot be disabled.
What is the use-case or motivation for changing an existing behavior?
I have a couple of tabs, which are rendered using *ngFor.
The data is retrieved from ngrx/store and upon any change of state, the tabs get rerendered and slide-in again, which sucks for UX.
Which versions of Angular, Material, OS, browsers are affected?
@angular/material: 2.0.0-beta.1
Have you tried adding trackBy to that *ngFor?
Yes but it works only partially.
I have a nested md-tab-group (one inside the other) and the trackBy helps on the parent md-tab-group.
The inner tab-group still gets rerendered on every change.
Even if you put trackBy on both?
Yes, even with two trackBys
<md-tab-group>
<md-tab [label]="group.name" *ngFor="let group of groups | async; trackBy group?.id">
<md-tab-group>
<md-tab [label]="table.name" *ngFor="let table of group.tables; trackBy table?.id">
<!-- ... -->
</md-tab>
</md-tab-group>
</md-tab>
</md-tab-group>
I work with ngrx and the table gets rebuilt and sorted on every change, will have to rethink my data structure.
In the meantime it would just be easier to disable the animation though.
Ok my bad, I have been googling trackBy a little more and I implemented it incorrectly.
I've changed the group?.id to trackByFn and in my controller I have:
trackByFn(index, item) { return item.id; }
The tabs don't get rerendered anymore, thanks.
Anyone knows how can I turn those animations off? I have "heavy" content inside tabs . It is fetched (and need to be fetched) from backend one every switch between tabs. Without animations it worked well but now it jam and freeze. I thought I could overrie CSS styles but it's defined inside Component decorator in tab-body.
My workaround for this, for AngularJS:
<md-tabs md-dynamic-height md-border-bottom md-selected="selectedIndex">
<md-tab label="one"></md-tab>
<md-tab label="two"></md-tab>
<md-tab label="three"></md-tab>
</md-tabs>
<section ng-if="selectedIndex === 0">ONE</section>
<section ng-if="selectedIndex === 1">TWO</section>
<section ng-if="selectedIndex === 2">THREE</section>
@BrunnerLivio Awesome, I made some changes for the new version:
<md-tab-group [(selectedIndex)]="selectedIndex">
<md-tab label="one"></md-tab>
<md-tab label="two"></md-tab>
<md-tab label="three"></md-tab>
</md-tab-group>
<section *ngIf="selectedIndex === 0">ONE</section>
<section *ngIf="selectedIndex === 1">TWO</section>
<section *ngIf="selectedIndex === 2">THREE</section>
Yup, it's a bit bizarre that this option wasn't provided. It looks great the first time you see the animation, but soon drives you mad...
@jelbourn
Any progress on this feature request? I don't mean trick, something like animation="false"
+1. I encountered need for animation switch when i tried to put element with fixed position into md-tab-body. In latest chrome fixed position will not work if any of parent elements have transform CSS property.
@mateuszwitkowski @jelbourn You can disable animation using @.disabled property which is introduced in angular 4.3.1.
just add code to your component
@Hostbinding('@.disabled') disabled = true
or in your html
<div [@.disabled]="expression"></div>
Here is working plnkr https://plnkr.co/edit/sVJM8H?p=preview
Thanks @lokeshdaiya
@.disabled works as expected for me! But actually I don't understand how does it work :thinking:
Because the tab buttons still have animations, but the tab content animation disabled as well!
I wonder if there is any performance concern for using @.disabled!
[@.disabled]="true" works nicely for me as well. Can someone explain how this works?
The tabs use the Angular animations framework for its animations. By using @.disabled, you are telling the framework not to perform animations for the tabs, which is as performant as you can get.
We should point out that certain components fail to work if you disable animation using the @.disabled property. E.g. the mat-sidenav component stops working:
https://stackblitz.com/edit/angular-material2-sidenav-disable-animation-issue
Issue: https://github.com/angular/material2/issues/7053
I'm facing issues with this approach. When I set [@.disabled]="true" for mat-tab-group and have a nested tab-group inside it disables animation for both, while I want only for the parent. Animation is also disabled for the expansion panel inside the second md-tab-group. It look like I'll have to use the previously stated ngIf approach.
[@.disabled]="true" works for components like tabs, but not works for Select component, any ideas?
+1 works for me and now have a new thing to learn in [@.disabled]="true". Thanks
cool