From 8f8ce778bd78a42076db33c886b4e623a17d4f15 Mon Sep 17 00:00:00 2001 From: Valentin Mihai Date: Wed, 23 Feb 2022 15:50:46 +0200 Subject: [PATCH] checked how many mat dialogs are opened on 'esc' event in BaseDialog instead of 'waitingForConfirmation' flag --- src/lib/dialog/base-dialog.component.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/lib/dialog/base-dialog.component.ts b/src/lib/dialog/base-dialog.component.ts index c4eb5f4..83f361b 100644 --- a/src/lib/dialog/base-dialog.component.ts +++ b/src/lib/dialog/base-dialog.component.ts @@ -1,5 +1,5 @@ import { Directive, HostListener, Injector, OnInit } from '@angular/core'; -import { MatDialogRef } from '@angular/material/dialog'; +import { MatDialog, MatDialogRef } from '@angular/material/dialog'; import { FormGroup } from '@angular/forms'; import { AutoUnsubscribe, hasFormChanged, IqserEventTarget } from '../utils'; import { ConfirmOptions } from '../misc'; @@ -25,8 +25,8 @@ export interface SaveOptions { export abstract class BaseDialogComponent extends AutoUnsubscribe implements OnInit { form!: FormGroup; initialFormValue; - protected readonly _dialogService: ConfirmationDialogService = this._injector.get(ConfirmationDialogService); - protected _waitingForConfirmation = false; + private readonly _dialogService: ConfirmationDialogService = this._injector.get(ConfirmationDialogService); + private readonly _dialog: MatDialog = this._injector.get(MatDialog); constructor(protected readonly _injector: Injector, protected readonly _dialogRef: MatDialogRef) { super(); @@ -62,7 +62,6 @@ export abstract class BaseDialogComponent extends AutoUnsubscribe implements OnI this._dialogRef.close(); } } - this._waitingForConfirmation = false; }); } else { this._dialogRef.close(); @@ -79,13 +78,12 @@ export abstract class BaseDialogComponent extends AutoUnsubscribe implements OnI @HostListener('window:keydown.Escape', ['$event']) onEscape(): void { - if (!this._waitingForConfirmation) { + if (this._dialog.openDialogs.length === 1) { this.close(); } } protected _openConfirmDialog() { - this._waitingForConfirmation = true; const dialogRef = this._dialogService.openDialog({ disableConfirm: !this.valid }); return firstValueFrom(dialogRef.afterClosed()); }