bug(Mat-Tabs): Mat-tabs on mat-dialog not working when selectedIndex change asynchronously
Reproduction
https://stackblitz.com/edit/mat-tabs-on-mat-dialog-problem
Steps to reproduce:
- Use mat-dialog for dialog
- Use mat-tabs for multiple tabs
- Use selectedIndex to select tabs dynamically
- Initialize selectedIndex value
- Change selectedIndex asynchronously
Expected Behavior
I will initially see the tab of the index that I initialize first. But when I change the selectedIndex, it will switch to the new tab of that index.
Actual Behavior
Asynchronously changed tabs contents will go blank. The tab contains blank content. But if I add 500ms with setTimeout it works. But without this setTimeout, it dosn't work
Environment
- Angular: 8 or 9
- CDK/Material: 8, 10
- Chrome, Firefox
- Ubuntu, Windows
Seems like a legit bug - it's not clear why the rendering is doing that. Will need to dive deeper. I tried seeing if animationDuration=0 helped, but the issue still was present
Was this ever resolved? I'm still seeing this issue
Was this ever resolved? I'm still seeing this issue
Don't think so, I also just encountered this issue
@mdrafee03 did you ever find a solution to this issue?
@mdrafee03 did you ever find a solution to this issue?
This worked for me and fit my project: https://stackoverflow.com/a/62661533/6370521
@mdrafee03 did you ever find a solution to this issue?
This worked for me and fit my project: https://stackoverflow.com/a/62661533/6370521
I'm using an automation test tool that selects the second tab once the dialog is open. Since this is a quick, automated selection, it causes this error where nothing in the second tab renders. The 2 working solutions I found are:
- Use a
setTimeout()to wait for the tab content to render, then change thethis.selectedIndexvalue. - Use the
<mat-tab-group *ngIf="selectedIndex!=undefined" [selectedIndex]="selectedIndex">solution. This also requires thethis.selectedIndexto be initialized as undefined, but then assignedthis.selectedIndex = 0in thengAfterViewInit()lifecylce callback. But this causes aError: NG0100: ExpressionChangedAfterItHasBeenCheckedError:
The issue is still present…
Just bumping this. I am still having this issue in Angular 17.2.0. It causes no tab to be selected on initial page load. From a business logic perspective this means I have two choices:
- Find a way to hack it and make it work
- Decide not to use mat tabs
So I think from a priority perspective, this is a higher priority than the issue leads onto