components icon indicating copy to clipboard operation
components copied to clipboard

[Table] Sort arrows are not rendered properly in tabs

Open kevincaradant opened this issue 9 years ago • 54 comments

Bug, feature request, or proposal:

BUG Plunker: https://plnkr.co/edit/Idc73Kn0ViLI4Qpsp98g?p=preview

When you set your sort by default as ASC or DESC like that:

@ViewChild(MatSort) mdSort: MatSort;

ngOnInit() {this.mdSort.start = 'desc';}

The arrow is just ugly ( 2 times on 3 ). If you click again on the sort icon, it's pretty :)

BTW: Under IE11 it's always ugly. Same issue or not I don't know

What is the current behavior?

image

What is the expected behavior?

image

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

Angular 4.4.3 OS: Windows 7 Pro 64 bits TS: 2.4.1 Material: 2.0.0-beta.11 Browser: Chrome V60

Is there anything else we should know?

Nothing #

kevincaradant avatar Sep 25 '17 12:09 kevincaradant

I was able to reproduce the issue and I suspect what is happening here is that you are setting an invalid direction (e.g. ascending instead of asc)

Plunker to show issue: https://plnkr.co/edit/vf61Yr6tvDtOlKRr9zeN?p=preview

Can you verify that this was the issue?

Adding PR #7378 that will throw an error if the direction is invalid.

andrewseguin avatar Sep 27 '17 22:09 andrewseguin

Hi

Good try, but I think it's not the problem.

In fact, I found something interesting. It's when I use a <md-tab> and if my <md-table> is not in the first tab (loaded on the load of the page), the initialization of arrow is bad. Sorry I didn't have the time to do a plunker now ( if you don't understand, I will try to do it begining with yours ) but the idea is something like that:

<mat-tab-group *ngIf="accountExist">
    <mat-tab label="{{'USER' | translate}}">
        <mat-card fxLayout="column">
          <mat-card-content>
            <app-info-user></app-info-user>  // my first <md-table> is inside this component
          </mat-card-content>
        </mat-card>
    </mat-tab>

    <mat-tab label="{{'FAMILY' | translate}}">
        <mat-card fxLayout="column">
          <mat-card-content>
            <app-families-user></app-families-user> // my second <md-table> is inside this component
          </mat-card-content>
        </mat-card>
    </mat-tab>
</mat-tab-group>

The second table "families" will have a ugly arrow even with with a sort "asc" or "desc"

kevincaradant avatar Sep 28 '17 08:09 kevincaradant

@andrewseguin , Have you seen my previous message, why this issue is closed ?

It's not the same problem, so the solution mentioned in your PR will throw only the error but I will continue to get this error because the name "asc" is correct. For me, it's just link to the <md-table> which is included in a <md-tab> :)

Regards

NB: I will try to do a plunkr

kevincaradant avatar Oct 01 '17 22:10 kevincaradant

Hey yeah - let's open this back up to figure out what's going on. Sounds like perhaps animations isn't firing off.

Definitely try and get a plunker going so we can dive into this. Thanks

andrewseguin avatar Oct 01 '17 22:10 andrewseguin

This is the plunker :)

https://plnkr.co/edit/Idc73Kn0ViLI4Qpsp98g?p=preview

Go on the second tab => "family"

kevincaradant avatar Oct 01 '17 22:10 kevincaradant

Great thanks for the repro. Looks like the states are being set properly but the animations framework isn't animating the arrow. I'll talk to the core animations guy to see if we can dive into this and see why it's not triggering.

andrewseguin avatar Oct 06 '17 23:10 andrewseguin

Hello, any news about this bug ? :)

kevincaradant avatar Nov 23 '17 10:11 kevincaradant

Coming soon - looks like this is similar to a wider issue with tabs not playing nice with Angular's content projection. In short, components in tabs are initialized without actually being on the DOM, which breaks for some animations (e.g. expansion panel). Sorry for the wait on this

andrewseguin avatar Nov 27 '17 19:11 andrewseguin

@andrewseguin, don't be sorry. I just asking the status about the issue even if I'm sure, there are some others issues (high priority) which need to be fixed ASAP. BTW, thank you for the explanations :)

kevincaradant avatar Nov 28 '17 00:11 kevincaradant

Still an issue on Angular 5.2.2 and Material 5.1.0

alexciesielski avatar Jan 30 '18 10:01 alexciesielski

Keep an eye on https://github.com/angular/material2/pull/8921 for the fix. When it's merged then you can make it so that your tabs load lazily which means Angular animations will work correctly for content in tabs

andrewseguin avatar Jan 30 '18 19:01 andrewseguin

It's a very very very bad bug for performance (@angular/material^5.2.0) It occured in mat-tabs, so the single solution is to hide these arrows why simply not to use images? It's simple and it will work

.mat-sort-header-arrow {
  display: none !important;
}

vladkalyuzhny avatar Feb 10 '18 15:02 vladkalyuzhny

Using 6.0.0 Beta and lazily-loaded tabs "fixes" the issue but it shouldn't be necessary (also, using lazy tabs is not necessarily wanted depending on the app)...

sielver avatar Feb 14 '18 13:02 sielver

I found a workaround for this:

The first time I change to the tab with the table, I call a method which does the following:

table.ngOnDestroy(); dataSource = new DataSource(data); // This is needed because ngOnDestroy disconnects the data source. table.ngOnInit();

Note that table is the MatTable object and dataSource is bound to the table: <mat-table [dataSource]="dataSource" matSort>

It's not a good solution and kind of a hack, but it works for me. Maybe this helps some other people too.

VangelisAlSghir avatar Feb 15 '18 15:02 VangelisAlSghir

@sielver not working unfortunately

ezgif-1-f950bcff00

In gif i have tried to show what is the real problem

vladkalyuzhny avatar Feb 22 '18 08:02 vladkalyuzhny

@androidovshchik I've had it working on my end. Not an ideal solution but no glitch to be seen.

See here for an example for wrapping tabs within <ng-template matTabContent>.

edit: fixed url

sielver avatar Feb 22 '18 09:02 sielver

@sielver solution is working(lazy loading) nicely, but put the mat-table in a separate new component, put a flag with *ngIf on the component tag, when you changeTab{ mat-tab-group(selectedTabChange) } to current turn on the flag. If you don't want to make a new component and want to use it on same component then @VangelisAlSghir works fine but inti/destroy is not a good solution

SaadAhmedSiddiqui avatar Feb 22 '18 11:02 SaadAhmedSiddiqui

+1, waiting for a clean solution or fixes

hoangnguyen208 avatar Mar 07 '18 13:03 hoangnguyen208

+1 still exists on 5.2.4 when table is wrapped in *ngIf:

image

<div *ngIf="expanded" @expandInOut>
    <mat-divider class="kd-on-top"></mat-divider>
    <mat-card-content class="kd-card-content"
                      [ngClass]="{'kd-card-content-table': role === 'table'}">
      ...
        <ng-content select="[content]"></ng-content>
      ...
    </mat-card-content>
   ...
  </div>

maciaszczykm avatar Mar 09 '18 09:03 maciaszczykm

@maciaszczykm Wrapping the table with *ngIf is equal to use <ng-template matTabContent>. I'm agree with @hoangnguyen208, prefer waiting a clean solution.

bastienlemaitre avatar Mar 12 '18 09:03 bastienlemaitre