Properly detach the dialog when rejecting it with `Esc`
authorAlexander Ebert <ebert@woltlab.com>
Wed, 3 Jan 2024 16:27:39 +0000 (17:27 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 3 Jan 2024 16:27:39 +0000 (17:27 +0100)
See https://www.woltlab.com/community/thread/303957-confirmationfactory-und-esc/

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

index f2a9ef4ba88ac1b29552e590ed13ec6826d79bc8..db991f29acddf7ba8eb253e1c530c0bee53b6dd7 100644 (file)
@@ -83,6 +83,10 @@ export class WoltlabCoreDialogElement extends HTMLElement {
   }
 
   #detachDialog(): void {
+    if (this.parentNode === null) {
+      return;
+    }
+
     const event = new CustomEvent("afterClose");
     this.dispatchEvent(event);
 
@@ -202,11 +206,10 @@ export class WoltlabCoreDialogElement extends HTMLElement {
     this.#dialog.addEventListener("close", () => {
       if (this.#dialog.returnValue === "") {
         // Dialog was programmatically closed.
-        return;
+      } else {
+        this.#dispatchPrimaryEvent();
       }
 
-      this.#dispatchPrimaryEvent();
-
       this.#detachDialog();
     });
 
index 06682859d59c0716d57833ffe87b9aa0fcebb2b3..4adf0baf7460d5417f84afe6617c523b097a8c52 100644 (file)
@@ -51,6 +51,9 @@ define(["require", "exports", "tslib", "../Dom/Util", "../Helper/PageOverlay", "
             this.#detachDialog();
         }
         #detachDialog() {
+            if (this.parentNode === null) {
+                return;
+            }
             const event = new CustomEvent("afterClose");
             this.dispatchEvent(event);
             (0, PageOverlay_1.releasePageOverlayContainer)(this.#dialog);
@@ -148,9 +151,10 @@ define(["require", "exports", "tslib", "../Dom/Util", "../Helper/PageOverlay", "
             this.#dialog.addEventListener("close", () => {
                 if (this.#dialog.returnValue === "") {
                     // Dialog was programmatically closed.
-                    return;
                 }
-                this.#dispatchPrimaryEvent();
+                else {
+                    this.#dispatchPrimaryEvent();
+                }
                 this.#detachDialog();
             });
             formControl.addEventListener("cancel", () => {