Skip to content

Sidebar active-page auto-expand doesn't sync the +/- toggle icon with visible children #7763

Description

@jstirnaman

Describe the issue

In the left sidebar nav tree, ancestor sections auto-expanded on page load (to
reveal the active page) show a mismatched toggle icon: the section displays
"+" (collapsed-looking) while its children are actually visible. Clicking the
icon then flips it to "-" (expanded-looking) while the children collapse —
the opposite of what the icon communicates.

Root cause

layouts/partials/sidebar.html, in the inline auto-expand script (~line
116-144), walks up from the active page's <li> to open every ancestor
ul.children:

var node = active.parentElement;
while (node && node.id !== 'nav-tree') {
  if (node.tagName === 'UL' && node.classList.contains('children')) {
    node.classList.add('open');
    var t = node.previousElementSibling;
    if (t && t.classList.contains('children-toggle')) t.classList.add('open');
  }
  node = node.parentElement;
}

node.previousElementSibling assumes .children-toggle immediately precedes
ul.children. But per layouts/partials/sidebar/nested-menu.html (lines
40-48), the markup order inside each <li> is:

<a class="children-toggle">...</a>
<a href="...">Name</a>
<ul class="children">...</ul>

So ul.children's previousElementSibling is the plain link <a>, not
.children-toggle — the t.classList.contains('children-toggle') check is
always false for every ancestor level, and the toggle icon never gets .open
added, even though ul.children does.

This only affects ancestor levels reached via the while loop. The
"own children" case a few lines above (128-132) is unaffected because it
queries the toggle directly: active.querySelector(':scope > .children-toggle').

Then assets/js/content-interactions.js's click handler
(leftNavInteractions()) toggles .open on both the icon and its sibling
.children together, so a click on a mismatched section flips the icon to
match its stale pre-click state instead of syncing to the actual (now
opposite) visibility — inverting the icon on every subsequent click for that
section.

Suggested fix

In the while loop, look up the toggle the same way the "own children" block
does, instead of relying on sibling order, e.g.:

var t = node.parentElement.querySelector(':scope > .children-toggle');

Relevant URLs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions