Skip to content

Commit

Permalink
Add comment
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardHelm committed Aug 1, 2024
1 parent 0de40cc commit 263f738
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libs/components/src/lib/dialog/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ export class Dialog extends FoundationElement {
_onKeyDown(event: KeyboardEvent) {
if ((event as KeyboardEvent).key === 'Escape' && this._openedAsModal) {
this._handleCloseRequest();

// Return false to .preventDefault() which will prevent the <dialog>'s cancel event from being fired.
// Otherwise, pressing ESC twice would close the <dialog> without the ability to prevent it.
// This is because subsequent close requests without "intervening user action" between them are not cancelable.
// See: https://html.spec.whatwg.org/multipage/interaction.html#close-watcher-infrastructure
return false;
}
return true;
Expand Down

0 comments on commit 263f738

Please sign in to comment.