Skip to content

Provide expand all | collapse all buttons #241

Open

Description

@wajihaparvez

Describe the bug

I guess this is more of a request than a bug report.

@kilfoyle came up with the idea for Expand all | Collapse all buttons to simplify the side navigation. Since all the H1s are expanded, navigating through the website could be overwhelming for users.

Expected behavior

We should provide Expand all | Collapse all buttons in the sidenav so that users can view just the top-level sections or all their children as they wish.

Steps to reproduce

No response

Tooling

  • docs-builder
  • migration tooling
  • I'm not sure

Activity

  1. leemthompo commented on Jan 22, 2025

    @leemthompo
    Member

    💡I wonder if the left-hand nav should have state. For example, say I specifically make 2 or 3 sections open, it would be nice to not lose this if I change pages.

  2. benironside commented on Jan 22, 2025

    @benironside

    Also, when you are in a page, and you collapse the section that page is in on the left nav menu, the nav menu will not have any indication of which page you're on. I think it would be beneficial if the section you're in went bold when you are on a page in that section.

  3. cotti commented on Jun 3, 2026

    @cotti
    Contributor

    AI triage

    Automated investigation against the current codebase. A human still needs to confirm before any code change.

    Original concern

    Add Expand all | Collapse all controls to the left side-navigation so readers can toggle between just the top-level sections and the full tree.

    Findings

    • src/Elastic.Documentation.Site/Navigation/_TocTreeNav.cshtml:48-89 — every folder renders a hidden <input type="checkbox" id="@folder.Id"> plus a <label>; expand/collapse is a pure CSS checkbox toggle. There is no "expand all / collapse all" markup anywhere, and no aggregate control.
    • src/Elastic.Documentation.Site/Assets/styles.css:173-179 — .nav-subtree is hidden and revealed only when its sibling .peer contains a :checked box, so each folder toggles independently with no global state to drive from.
    • src/Elastic.Documentation.Site/Navigation/_TocTree.cshtml:9-13 — there is a sticky top-0 header (search + section dropdown) above #nav-tree (_TocTree.cshtml:65-75); that's the natural home for an Expand/Collapse-all control, but nothing is rendered there today.
    • src/Elastic.Documentation.Site/Assets/pages-nav.ts:33-42 — expandAllParents() only expands the ancestors of the current page; there is no "expand everything" routine that a button could reuse.
    • (re: @leemthompo's "keep my open sections across pages") src/Elastic.Documentation.Site/Assets/pages-nav.ts:10-31,154-159 — expansion state is already persisted to sessionStorage (NAV_STATE_KEY = 'nav-expanded') via saveNavState/restoreNavState, but only when isDevMode() is true (pages-nav.ts:6-8,125-127). So the groundwork exists but is gated to local docs-builder serve, not production readers. Added in PR #2982 (commit 5c04bd64, 2026-03-30).
    • (re: @benironside's "show which section I'm in") the current page is highlighted via .current (styles.css:428-430 → text-blue-elastic font-semibold), ancestor folder links pick up color through group-[.current]/li (styles.css:151-156), and the subtree connector line darkens when it contains .current (styles.css:188-191). However a collapsed ancestor folder whose child is the current page is not itself bolded unless the folder link is the current page, so this part of the thread is only partly addressed.

    Verdict

    Needs stakeholder input

    The requested buttons do not exist — the side-nav is a CSS-only, per-folder checkbox toggle with no aggregate control (_TocTreeNav.cshtml:48-89, styles.css:173-179). Wiring up "Expand all / Collapse all" is mechanically small (a couple of buttons in the sticky header that check/uncheck all #nav-tree input[type=checkbox]), but it adds reader-visible chrome to every page and overlaps with several adjacent nav decisions raised in the thread (persisting state across pages, active-section indication) and in sibling issues. Those are UX/frontend calls, so they should get a design sign-off before implementation rather than being shipped as a silent tweak.

    Proposal

    Mechanically the change is contained, but the design questions need an owner:

    For UX / frontend:

    • Where do the controls live — in the sticky _TocTree.cshtml header, inline near the section dropdown, or per-section? One combined toggle or two separate buttons?
    • Should "Expand all / Collapse all" operate on the whole tree or only within the current top-level section?
    • Should the chosen state persist across page loads? saveNavState/restoreNavState already implement sessionStorage persistence but are gated to isDevMode() — do we ungate that for all readers (addresses @leemthompo), and is sessionStorage (per-tab) the right scope vs localStorage?
    • Accessibility/mobile: keyboard focus and aria state for the new control, and behavior inside the mobile hamburger panel.
    • Should we also bold/highlight a collapsed ancestor folder when one of its descendants is the current page (addresses @benironside)?

    If UX agrees on placement + scope, the implementation is roughly: add the control(s) to _TocTree.cshtml, add a handler in pages-nav.ts that toggles all #nav-tree input[type="checkbox"], and (optionally) reuse the existing saveNavState logic outside dev mode.

    Related issues

    This sits in a cluster around side-nav expand/collapse behavior:

    • Open: #1150 (collapse the left nav entirely) — adjacent control on the same surface.
    • Closed precedents on controlling expand/collapse state: #456, #899, #863 (default/initial collapsed state), and #524 (expand/collapse mis-wired for similar titles).

    Worth confirming whether #456/#899/#863 were resolved by a design decision that also covers this request.

    Notes

    • Partial groundwork already merged: per-folder state persistence via sessionStorage, dev-mode only — PR #2982 (commit 5c04bd64).
    • The issue carries a low hanging fruit label; that's accurate for the code, but the bundled UX decisions (placement, persistence scope, active-section indication) are what make it stakeholder-gated rather than a drop-in quick fix.
  4. added
    ai-triaged
    ai:ux-question
    on Jun 3, 2026
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

    ai-triagedai:ux-questionenhancementlow hanging fruit

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions