Trigger the `cancel` event when the dialog is closed with `Esc`
authorAlexander Ebert <ebert@woltlab.com>
Fri, 22 Dec 2023 17:04:09 +0000 (18:04 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 22 Dec 2023 17:04:09 +0000 (18:04 +0100)
See https://www.woltlab.com/community/thread/303492-confirmationfactory-und-escape/

ts/WoltLabSuite/Core/Element/woltlab-core-dialog.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Element/woltlab-core-dialog.js

index ca25d8df426a1f56eed22f1bcee5d48c8fbf1e5e..f2a9ef4ba88ac1b29552e590ed13ec6826d79bc8 100644 (file)
@@ -273,11 +273,9 @@ export class WoltlabCoreDialogElement extends HTMLElement {
     this.#dialog.classList.add("dialog");
     this.#dialog.setAttribute("aria-labelledby", DomUtil.identify(this.#title));
 
-    this.#dialog.addEventListener("cancel", (event) => {
-      if (!this.#shouldClose()) {
-        event.preventDefault();
-        return;
-      }
+    this.#dialog.addEventListener("cancel", () => {
+      const event = new CustomEvent("cancel");
+      this.dispatchEvent(event);
 
       this.#detachDialog();
     });
index f780c88971b470c183e6b68b49829ab79a9feec3..06682859d59c0716d57833ffe87b9aa0fcebb2b3 100644 (file)
@@ -207,11 +207,9 @@ define(["require", "exports", "tslib", "../Dom/Util", "../Helper/PageOverlay", "
             this.#dialog.append(doc);
             this.#dialog.classList.add("dialog");
             this.#dialog.setAttribute("aria-labelledby", Util_1.default.identify(this.#title));
-            this.#dialog.addEventListener("cancel", (event) => {
-                if (!this.#shouldClose()) {
-                    event.preventDefault();
-                    return;
-                }
+            this.#dialog.addEventListener("cancel", () => {
+                const event = new CustomEvent("cancel");
+                this.dispatchEvent(event);
                 this.#detachDialog();
             });
             // Close the dialog by clicking on the backdrop.