Detect active menu items that have no children
authorAlexander Ebert <ebert@woltlab.com>
Thu, 23 Jun 2022 16:31:05 +0000 (18:31 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 23 Jun 2022 16:31:05 +0000 (18:31 +0200)
Links with children have the `active` class set on them, but links without have it placed on the parent instead.

See https://www.woltlab.com/community/thread/296045-mobiles-hauptmen%C3%BC-teilweise-nicht-vorausgew%C3%A4hlt-wenn-man-auf-einer-unterseite-is/

ts/WoltLabSuite/Core/Acp/Ui/Page/Menu/Main/Backend.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/Page/Menu/Main/Backend.js

index c06a2b47cbc9411acd0fd4bd5ecd233a8762e0c9..8a8e576e5403af8ac0237b6be90db1acfb24be61 100644 (file)
@@ -29,8 +29,13 @@ function getMenuItems(category: HTMLOListElement): MenuItem[] {
   return Array.from(category.querySelectorAll(".acpPageSubMenuLink")).map((link: HTMLAnchorElement) => {
     const children = getMenuItemActions(link);
 
+    let active = link.classList.contains("active");
+    if (children.length === 0 && link.parentElement!.classList.contains("active")) {
+      active = true;
+    }
+
     return {
-      active: link.classList.contains("active"),
+      active,
       children,
       counter: 0,
       depth: 2,
index 3044adbb9f1a55c17da83034e96ba72e1637f4bb..43ba1d4373ca12d280c6a90ce6e898ffe0aea42a 100644 (file)
@@ -27,8 +27,12 @@ define(["require", "exports"], function (require, exports) {
     function getMenuItems(category) {
         return Array.from(category.querySelectorAll(".acpPageSubMenuLink")).map((link) => {
             const children = getMenuItemActions(link);
+            let active = link.classList.contains("active");
+            if (children.length === 0 && link.parentElement.classList.contains("active")) {
+                active = true;
+            }
             return {
-                active: link.classList.contains("active"),
+                active,
                 children,
                 counter: 0,
                 depth: 2,