From da086cdaa648d1d35a9eb16ee23cb223e1de2316 Mon Sep 17 00:00:00 2001 From: Valentin Mihai Date: Wed, 20 Dec 2023 10:32:18 +0200 Subject: [PATCH] RED-6960 - Enter should always confirm a modal window --- src/lib/dialog/base-dialog.component.ts | 4 ++-- .../confirmation-dialog.component.html | 2 +- .../confirmation-dialog.component.ts | 11 ++++++++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/lib/dialog/base-dialog.component.ts b/src/lib/dialog/base-dialog.component.ts index eb9ebec..c1cb094 100644 --- a/src/lib/dialog/base-dialog.component.ts +++ b/src/lib/dialog/base-dialog.component.ts @@ -84,9 +84,9 @@ export abstract class BaseDialogComponent implements AfterViewInit, OnDestroy { @HostListener('window:keydown.Enter', ['$event']) onEnter(event: KeyboardEvent): void { - event?.stopImmediatePropagation(); const node = (event.target as IqserEventTarget).localName?.trim()?.toLowerCase(); - if (this.valid && !this.disabled && this.changed && node === TARGET_NODE) { + if (this.valid && !this.disabled && this.changed && node === TARGET_NODE && this.#dialog.openDialogs.length === 1) { + event?.stopImmediatePropagation(); this.save(); } } diff --git a/src/lib/dialog/confirmation-dialog/confirmation-dialog.component.html b/src/lib/dialog/confirmation-dialog/confirmation-dialog.component.html index 015944e..1123f7e 100644 --- a/src/lib/dialog/confirmation-dialog/confirmation-dialog.component.html +++ b/src/lib/dialog/confirmation-dialog/confirmation-dialog.component.html @@ -37,7 +37,7 @@ > ; export const ConfirmOptions = { CONFIRM: 1, - // TODO: this should be renamed to CONFIRM_WITH_ACTION - SECOND_CONFIRM: 2, + CONFIRM_WITH_ACTION: 2, DISCARD_CHANGES: 3, } as const; @@ -111,7 +110,7 @@ export class ConfirmationDialogComponent { get confirmOption(): ConfirmOption { if (!this.config.checkboxesValidation && this.config.checkboxes[0]?.value) { - return ConfirmOptions.SECOND_CONFIRM; + return ConfirmOptions.CONFIRM_WITH_ACTION; } return ConfirmOptions.CONFIRM; } @@ -156,4 +155,10 @@ export class ConfirmationDialogComponent { Object.assign(obj, { [key]: value }); }); } + + @HostListener('window:keydown.Enter', ['$event']) + onEnter(event: KeyboardEvent): void { + event?.stopImmediatePropagation(); + this.confirm(ConfirmOptions.CONFIRM); + } }