Skip to content

Commit

Permalink
docs(side nav): fix for top level items with no children (#922)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrispymm authored Nov 13, 2024
1 parent e592dcc commit 3c14ffb
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions docs/assets/javascript/collapsible-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class CollapsibleNav extends HTMLElement {
$button.insertAdjacentHTML("afterbegin", $link.innerHTML);
$item.replaceChild($button, $link);
if (!this.isOpen($item)) {
this.close($item)
this.close($item);
}
});

Expand All @@ -36,10 +36,8 @@ export default class CollapsibleNav extends HTMLElement {
if (!$button) return;
const $item = $button.parentNode;
if (!$item) return;
console.log($item)
console.log(this.isOpen($item))

if (this.isOpen($item)) {
console.log($item)
this.close($item);
} else {
this.closeOpenItems();
Expand All @@ -54,27 +52,26 @@ console.log($item)
open($item) {
const $button = $item.querySelector("button");
const $list = $item.querySelector("ul");
if (!$button) return;
if (!$list) return;

$list.hidden = false;
$item.classList.add(this.openClass);
$button.setAttribute("aria-expanded", true);
}

close($item) {
console.log($item)
const $button = $item.querySelector("button");
const $list = $item.querySelector("ul");
console.log($item)
console.log($button)
console.log($list)
if (!$button) return;
if (!$list) return;

$list.hidden = true;
$item.classList.remove(this.openClass);
$button.setAttribute("aria-expanded", false);
}

closeOpenItems() {
console.log(this.openItems)
this.openItems.forEach((item) => this.close(item));
}

Expand All @@ -83,6 +80,6 @@ console.log(this.openItems)
}

get openItems() {
return this.querySelectorAll(`.${this.openClass}`);
return this.querySelectorAll(`li:has(ul).${this.openClass}`);
}
}

0 comments on commit 3c14ffb

Please sign in to comment.