I need to delay the changing of the MatTab
until a confirmation is provided. I am using MatDialog
for this confirmation. The problem is that the tab switches before the user clicks "Yes" on the confirmation dialog.
For instance, when I try to switch from the income tab to the adjustment tab, I want the confirmation popup to appear first. However, currently, the popup only shows up after I have already moved to the adjustment tab.
https://i.sstatic.net/YVeiH.png
This is my component template:
<mat-tab-group (click)="tabClick($event)">
<mat-tab *ngFor="let tab of tabs; let index = index" [label]="tab">
<app-spread></app-spread>
</mat-tab>
</mat-tab-group>
This is the relevant method in my component ts file (onClick's method):
tabClick(clickEvent: any) {
if (clickEvent.target.innerText != 'First') {
this.confirm();
}
}
public async confirm() {
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
maxHeight: '200px',
maxWidth: '767px',
width: '360px',
disableClose: true,
data: {
title: 'Confirmation Message',
content:
'There are valid statements that are not Final. Set the statements as Final?'
}
});
const res = dialogRef.afterClosed().subscribe(result => {
if (result === 1) {
//TODO need to change the tab
} else {
//TODO no need to change the tab
}
});
}