Incorrect alignment of positioned elements when they are hidden
authorAlexander Ebert <ebert@woltlab.com>
Thu, 26 Aug 2021 14:06:18 +0000 (16:06 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 26 Aug 2021 14:06:18 +0000 (16:06 +0200)
The calculation did not consider the `display` attribute, causing the elements dimensions to be considered as `0x0` for the purpose of the calculation.

See https://community.woltlab.com/thread/291896-beitragsoptionen-verschoben/

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

index 864f0257993cce8706f7cd87ede56a144de741d0..9b0ee7cd7a2d890b3e20d4d8241b41ee72034928 100644 (file)
@@ -176,6 +176,13 @@ export function set(element: HTMLElement, referenceElement: HTMLElement, options
     options.allowFlip = "both";
   }
 
+  let savedDisplayValue: string | undefined = undefined;
+  if (window.getComputedStyle(element).display === "none") {
+    savedDisplayValue = element.style.getPropertyValue("display");
+
+    element.style.setProperty("display", "block");
+  }
+
   // Place the element in the upper left corner to prevent calculation issues due to possible scrollbars.
   DomUtil.setStyles(element, {
     bottom: "auto !important",
@@ -295,6 +302,14 @@ export function set(element: HTMLElement, referenceElement: HTMLElement, options
 
   DomUtil.show(element);
   element.style.removeProperty("visibility");
+
+  if (savedDisplayValue !== undefined) {
+    if (savedDisplayValue === "") {
+      element.style.removeProperty("display");
+    } else {
+      element.style.setProperty("display", savedDisplayValue);
+    }
+  }
 }
 
 export type AllowFlip = "both" | "horizontal" | "none" | "vertical";
index 0ebaf3e897808368e57a8c6ef44a3c159fcef82d..b5e60e5483c3aa1612faf1ccb5785762edf46718 100644 (file)
@@ -122,6 +122,11 @@ define(["require", "exports", "tslib", "../Core", "../Dom/Traverse", "../Dom/Uti
         if (["both", "horizontal", "vertical", "none"].indexOf(options.allowFlip) === -1) {
             options.allowFlip = "both";
         }
+        let savedDisplayValue = undefined;
+        if (window.getComputedStyle(element).display === "none") {
+            savedDisplayValue = element.style.getPropertyValue("display");
+            element.style.setProperty("display", "block");
+        }
         // Place the element in the upper left corner to prevent calculation issues due to possible scrollbars.
         Util_1.default.setStyles(element, {
             bottom: "auto !important",
@@ -214,6 +219,14 @@ define(["require", "exports", "tslib", "../Core", "../Dom/Traverse", "../Dom/Uti
         });
         Util_1.default.show(element);
         element.style.removeProperty("visibility");
+        if (savedDisplayValue !== undefined) {
+            if (savedDisplayValue === "") {
+                element.style.removeProperty("display");
+            }
+            else {
+                element.style.setProperty("display", savedDisplayValue);
+            }
+        }
     }
     exports.set = set;
 });