import * as Language from "../../../Language";
import DomUtil from "../../../Dom/Util";
+type MenuItemDepth = 0 | 1 | 2;
+
type MenuItem = {
active: boolean;
children: MenuItem[];
counter: number;
+ depth: MenuItemDepth;
link?: string;
title: string;
};
-function normalizeMenuItem(menuItem: HTMLElement): MenuItem {
+function normalizeMenuItem(menuItem: HTMLElement, depth: MenuItemDepth): MenuItem {
const anchor = menuItem.querySelector(".boxMenuLink") as HTMLAnchorElement;
const title = anchor.querySelector(".boxMenuLinkTitle")!.textContent as string;
const subMenu = menuItem.querySelector("ol");
let children: MenuItem[] = [];
if (subMenu instanceof HTMLOListElement) {
+ let childDepth = depth;
+ if (childDepth < 2) {
+ childDepth = (depth + 1) as MenuItemDepth;
+ }
+
children = Array.from(subMenu.children).map((subMenuItem: HTMLElement) => {
- return normalizeMenuItem(subMenuItem);
+ return normalizeMenuItem(subMenuItem, childDepth);
});
}
active,
children,
counter,
+ depth,
link,
title,
};
private buildMenu(boxMenu: HTMLElement): HTMLElement {
const menuItems: MenuItem[] = Array.from(boxMenu.children).map((element: HTMLElement) => {
- return normalizeMenuItem(element);
+ return normalizeMenuItem(element, 0);
});
const nav = document.createElement("nav");
private buildMenuItem(menuItem: MenuItem): HTMLLIElement {
const listItem = document.createElement("li");
+ listItem.dataset.depth = menuItem.depth.toString();
listItem.classList.add("pageMenuMainItem");
if (menuItem.link) {
listItem.append(link);
} else {
- const label = document.createElement("span");
+ const label = document.createElement("a");
+ label.classList.add("pageMenuMainItemLabel");
+ label.href = "#";
label.textContent = menuItem.title;
+ label.addEventListener("click", (event) => {
+ event.preventDefault();
+
+ const button = label.nextElementSibling as HTMLAnchorElement;
+ button.click();
+ });
+
+ // The button to expand the link group is used instead.
+ label.setAttribute("aria-hidden", "true");
listItem.append(label);
}
button.setAttribute("role", "button");
button.setAttribute("aria-expanded", "false");
button.setAttribute("aria-controls", menuId);
- button.setAttribute("aria-label", Language.get("TODO"));
button.innerHTML = '<span class="icon icon24 fa-angle-down" aria-hidden="true"></span>';
+ let ariaLabel = menuItem.title;
+ if (menuItem.link) {
+ ariaLabel = Language.get("TODO");
+ }
+ button.setAttribute("aria-label", ariaLabel);
+
const list = this.buildMenuItemList(menuItem.children);
list.id = menuId;
list.hidden = true;
Container_1 = (0, tslib_1.__importDefault)(Container_1);
Language = (0, tslib_1.__importStar)(Language);
Util_1 = (0, tslib_1.__importDefault)(Util_1);
- function normalizeMenuItem(menuItem) {
+ function normalizeMenuItem(menuItem, depth) {
const anchor = menuItem.querySelector(".boxMenuLink");
const title = anchor.querySelector(".boxMenuLinkTitle").textContent;
let counter = 0;
const subMenu = menuItem.querySelector("ol");
let children = [];
if (subMenu instanceof HTMLOListElement) {
+ let childDepth = depth;
+ if (childDepth < 2) {
+ childDepth = (depth + 1);
+ }
children = Array.from(subMenu.children).map((subMenuItem) => {
- return normalizeMenuItem(subMenuItem);
+ return normalizeMenuItem(subMenuItem, childDepth);
});
}
// `link.href` represents the computed link, not the raw value.
active,
children,
counter,
+ depth,
link,
title,
};
}
buildMenu(boxMenu) {
const menuItems = Array.from(boxMenu.children).map((element) => {
- return normalizeMenuItem(element);
+ return normalizeMenuItem(element, 0);
});
const nav = document.createElement("nav");
nav.classList.add("pageMenuMainNavigation");
}
buildMenuItem(menuItem) {
const listItem = document.createElement("li");
+ listItem.dataset.depth = menuItem.depth.toString();
listItem.classList.add("pageMenuMainItem");
if (menuItem.link) {
const link = document.createElement("a");
listItem.append(link);
}
else {
- const label = document.createElement("span");
+ const label = document.createElement("a");
+ label.classList.add("pageMenuMainItemLabel");
+ label.href = "#";
label.textContent = menuItem.title;
+ label.addEventListener("click", (event) => {
+ event.preventDefault();
+ const button = label.nextElementSibling;
+ button.click();
+ });
+ // The button to expand the link group is used instead.
+ label.setAttribute("aria-hidden", "true");
listItem.append(label);
}
if (menuItem.counter > 0) {
button.setAttribute("role", "button");
button.setAttribute("aria-expanded", "false");
button.setAttribute("aria-controls", menuId);
- button.setAttribute("aria-label", Language.get("TODO"));
button.innerHTML = '<span class="icon icon24 fa-angle-down" aria-hidden="true"></span>';
+ let ariaLabel = menuItem.title;
+ if (menuItem.link) {
+ ariaLabel = Language.get("TODO");
+ }
+ button.setAttribute("aria-label", ariaLabel);
const list = this.buildMenuItemList(menuItem.children);
list.id = menuId;
list.hidden = true;
}
}
+.pageMenuMainItemLabel,
.pageMenuMainItemLink {
align-items: center;
color: inherit;
}
}
+.pageMenuMainItemLabel + .pageMenuMainItemToggle::before {
+ display: none;
+}
+
.pageMenuMainItemList {
grid-area: list;
}
-.pageMenuMainItem .pageMenuMainItemList {
+.pageMenuMainItem[data-depth="1"],
+.pageMenuMainItem[data-depth="2"] {
+ border-bottom-width: 0;
+
+ .pageMenuMainItemLabel,
+ .pageMenuMainItemLink {
+ font-weight: 400;
+ min-height: 34px;
+ }
+
+ .pageMenuMainItemToggle::before {
+ bottom: 5px;
+ top: 5px;
+ }
+}
+
+.pageMenuMainItem[data-depth="0"] .pageMenuMainItemList {
padding: 10px 0 20px 0;
+}
- .pageMenuMainItem {
- border-bottom-width: 0;
+.pageMenuMainItem[data-depth="1"] {
+ .pageMenuMainItemList {
+ padding: 10px 0;
}
+ .pageMenuMainItemLabel,
.pageMenuMainItemLink {
- font-weight: 400;
- min-height: 34px;
padding-left: 20px;
}
}
+.pageMenuMainItem[data-depth="2"] {
+ .pageMenuMainItemList {
+ padding: 0;
+ }
+
+ .pageMenuMainItemLabel,
+ .pageMenuMainItemLink {
+ padding-left: 30px;
+ }
+}
+
.pageMenuUserTabContainer {
display: flex;
flex-direction: column;