Skip to content

Commit

Permalink
feat(dialogue): esc cancel animation
Browse files Browse the repository at this point in the history
  • Loading branch information
azabroflovski committed May 8, 2024
1 parent 5d1539a commit e8923ea
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/lib/dialogue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface DialogueOptions {
*/
export class Dialogue {
/**
* The HTML dialogue element.
* The HTML dialog element.
*/
protected dialog: HTMLDialogueElement | undefined = undefined

Expand Down Expand Up @@ -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.
Expand All @@ -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
}
Expand Down

0 comments on commit e8923ea

Please sign in to comment.