RED-6960 - Enter should always confirm a modal window

This commit is contained in:
Valentin Mihai 2023-12-20 10:32:18 +02:00
parent 7f09e57248
commit da086cdaa6
3 changed files with 11 additions and 6 deletions

View File

@ -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();
}
}

View File

@ -37,7 +37,7 @@
></iqser-icon-button>
<iqser-icon-button
(action)="confirm(confirmOptions.SECOND_CONFIRM)"
(action)="confirm(confirmOptions.CONFIRM_WITH_ACTION)"
*ngIf="config.alternativeConfirmationText"
[disabled]="config.requireInput && confirmationDoesNotMatch()"
[label]="config.alternativeConfirmationText"

View File

@ -18,8 +18,7 @@ export type TitleColor = ValuesOf<typeof TitleColors>;
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);
}
}