From e8923ea33c02f57623efcecc237af1786c5a0bcb Mon Sep 17 00:00:00 2001 From: azabroflovski Date: Wed, 8 May 2024 17:33:04 +0500 Subject: [PATCH] feat(dialogue): esc cancel animation --- src/lib/dialogue.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/lib/dialogue.ts b/src/lib/dialogue.ts index 8fcdd34..310f867 100644 --- a/src/lib/dialogue.ts +++ b/src/lib/dialogue.ts @@ -9,7 +9,7 @@ export interface DialogueOptions { */ export class Dialogue { /** - * The HTML dialogue element. + * The HTML dialog element. */ protected dialog: HTMLDialogueElement | undefined = undefined @@ -41,9 +41,21 @@ export class Dialogue { this.dialog.addEventListener('keydown', this.preventEscClose) this.dialog.addEventListener('pointerdown', this.onClickInsideDialog) + this.dialog.addEventListener('cancel', this.onCancel.bind(this)) } } + + /** + * Handles the cancellation event. + * @param {Event} event - The event object. + * @returns {void} + */ + private onCancel(event: Event): void { + event.preventDefault() + this.close() + } + /** * Handles click inside the dialogue box. * @param {MouseEvent} event - The click event. @@ -59,6 +71,7 @@ export class Dialogue { * @param {KeyboardEvent} event - The keydown event. */ private preventEscClose(event: KeyboardEvent) { + console.log('123') if (event.key === 'Escape') event.preventDefault() // Prevent the default action of closing the dialog }