Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

305
Views
Slate Docs function to keep navigation accordion open when clicking on other links in sidebar

For UX, there may be times where multiple sections need to be open at once in the sidebar. Currently, when another section header is clicked in the sidebar, other sections collapse. How do i make it so the all the sections are open and close only when i click on the section header itself

enter image description here

enter image description here

This is the code that handles this:

var $best = $toc.find("[href='" + best + "']").first();

  if (!$best.hasClass("active")) {
    // .active is applied to the ToC link we're currently on, and its parent <ul>s selected by tocListSelector
    // .active-expanded is applied to the ToC links that are parents of this one
    $toc.find(".active").removeClass("active");
    $toc.find(".active-parent").removeClass("active-parent");
    $best.addClass("active");
    $best
      .parents(tocListSelector)
      .addClass("active")
      .siblings(tocLinkSelector)
      .addClass("active-parent");
    $best.siblings(tocListSelector).addClass("active");
    $toc.find(tocListSelector).filter(":not(.active)").slideUp(150);
    $toc.find(tocListSelector).filter(".active").slideDown(150);
    if (window.history.replaceState) {
      window.history.replaceState(null, "", best);
    }
    var thisTitle = $best.data("title");
    if (thisTitle !== undefined && thisTitle.length > 0) {
      document.title =
        thisTitle.replace(htmlPattern, "") + " – " + originalTitle;
    } else {
      document.title = originalTitle;
    }
  }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The 2 following lines are where the previously selected section is closed.

    $toc.find(".active").removeClass("active");
    $toc.find(".active-parent").removeClass("active-parent");

Comment them out and every section will remind open.

EDIT: to be able to close the section when you click on it you need to replace .addClass method by toggleClass documentation. This way the active class is added if not present and remove in the opposite case.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!