components icon indicating copy to clipboard operation
components copied to clipboard

[Tabs] Add ability to disable animations

Open alexciesielski opened this issue 9 years ago • 44 comments

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

alexciesielski avatar Jan 18 '17 10:01 alexciesielski

Have you tried adding trackBy to that *ngFor?

fxck avatar Jan 18 '17 13:01 fxck

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.

alexciesielski avatar Jan 19 '17 08:01 alexciesielski

Even if you put trackBy on both?

fxck avatar Jan 19 '17 08:01 fxck

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.

alexciesielski avatar Jan 19 '17 08:01 alexciesielski

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.

alexciesielski avatar Jan 19 '17 08:01 alexciesielski

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.

mateuszwitkowski avatar Feb 17 '17 12:02 mateuszwitkowski

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 avatar May 09 '17 11:05 BrunnerLivio

@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>

sharpevo avatar May 12 '17 03:05 sharpevo

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...

MikeInSwitzerland avatar Jun 20 '17 08:06 MikeInSwitzerland

@jelbourn Any progress on this feature request? I don't mean trick, something like animation="false"

m98 avatar Jun 28 '17 11:06 m98

+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.

VasilenkoAlex avatar Jul 19 '17 13:07 VasilenkoAlex

@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

lokeshdaiya avatar Jul 28 '17 09:07 lokeshdaiya

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!

m98 avatar Aug 09 '17 10:08 m98

[@.disabled]="true" works nicely for me as well. Can someone explain how this works?

rich4756 avatar Sep 20 '17 22:09 rich4756

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.

andrewseguin avatar Oct 19 '17 18:10 andrewseguin

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

tw3 avatar Oct 27 '17 14:10 tw3

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.

tarasbobak avatar Nov 06 '17 16:11 tarasbobak

[@.disabled]="true" works for components like tabs, but not works for Select component, any ideas?

MigCoder avatar Nov 16 '17 06:11 MigCoder

+1 works for me and now have a new thing to learn in [@.disabled]="true". Thanks

gotstu avatar Nov 28 '17 21:11 gotstu

cool

finalxcode avatar Dec 01 '17 08:12 finalxcode