Prevent updates to the dialog position during initialization
authorAlexander Ebert <ebert@woltlab.com>
Mon, 21 Aug 2023 08:50:38 +0000 (10:50 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 21 Aug 2023 08:50:38 +0000 (10:50 +0200)
The initial value only needs to be set once, all other cases are already handled by the `ResizeObserver`, causing race conditions.

See https://www.woltlab.com/community/thread/301273-the-position-of-the-edit-thread-menu-is-not-always-centred/

ts/WoltLabSuite/Core/Ui/Dialog.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js

index ace02fe8d2c3e05b26127ed2d93375f81268f944..3c265d68552f0982368ae0724bf59e403cb3ccd8 100644 (file)
@@ -627,8 +627,10 @@ const UiDialog = {
     const maximumHeight = window.innerHeight * (_dialogFullHeight ? 1 : 0.8) - unavailableHeight;
     contentContainer.style.setProperty("max-height", `${~~maximumHeight}px`, "");
 
-    const offset = Math.floor(data.dialog.getBoundingClientRect().width / 2);
-    data.dialog.style.setProperty("--translate-x", `-${offset}px`);
+    if (data.dialog.style.getPropertyValue("--translate-x") === "") {
+      const offset = Math.floor(data.dialog.getBoundingClientRect().width / 2);
+      data.dialog.style.setProperty("--translate-x", `-${offset}px`);
+    }
 
     const callbackObject = _dialogToObject.get(id);
     //noinspection JSUnresolvedVariable
index c481bd3c2a324757d3acbd585148fc18dc82af87..5320f5b9aeaa7a27fb09bc12b00c4156812bb6a9 100644 (file)
@@ -516,8 +516,10 @@ define(["require", "exports", "tslib", "../Core", "../Dom/Change/Listener", "./S
             unavailableHeight += Util_1.default.outerHeight(data.header);
             const maximumHeight = window.innerHeight * (_dialogFullHeight ? 1 : 0.8) - unavailableHeight;
             contentContainer.style.setProperty("max-height", `${~~maximumHeight}px`, "");
-            const offset = Math.floor(data.dialog.getBoundingClientRect().width / 2);
-            data.dialog.style.setProperty("--translate-x", `-${offset}px`);
+            if (data.dialog.style.getPropertyValue("--translate-x") === "") {
+                const offset = Math.floor(data.dialog.getBoundingClientRect().width / 2);
+                data.dialog.style.setProperty("--translate-x", `-${offset}px`);
+            }
             const callbackObject = _dialogToObject.get(id);
             //noinspection JSUnresolvedVariable
             if (callbackObject !== undefined && typeof callbackObject._dialogSubmit === "function") {