8000 Add Table of Contents sidebar for desktop and top section for mobile by bmndc · Pull Request #1627 · just-the-docs/just-the-docs · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@bmndc
Copy link
@bmndc bmndc commented Mar 16, 2025

#1546 but with upstream changes

Add a Table of Contents sidebar to the right of main content. When enabled, the layout will be shifted left to accommodate the new sidebar (unless on smaller screens where ToC will display as a side/top panel).

You can use unordered list and ordered list to represent ToC, and add {:.no_toc} to a heading to hide it from the ToC.

Switches when the screen width is larger than $nav-width + $content-width + $toc-width (set as mq(xl)).

Because of the shift in layout, the ToC sidebar is opt-out per page or layout. Once enabled in _config.yml, the feature will be enabled site-wide and you need to set the flag on a page or layout to disable the ToC sidebar for that page or layout. Likewise, if you wish to use the ToC sidebar for just one page, you have to enable the feature site-wide.

Kudos to allejo for making this possible with jekyll-toc (MIT).

Screenshots

Large desktops

Screenshot of the main page of the Just the Docs website, with the sidebar to the right containing the Table of Contents list

Small desktops and Tablets

style: "float" (default) style: "side"
Screenshot of the main page of the Just the Docs website, with the Table of Contents list appearing as a floating panel to the top right of main content Screenshot of the main page of the Just the Docs website, with the Table of Contents list appearing as a side panel on the right of main content

Clicking on the overlay should also close the side panel.

Phones

Screenshot of the main page of the Just the Docs website, with the Table of Contents opener button appearing as a header Screenshot of the main page of the Just the Docs website, with the Table of Contents list appearing as a floating panel to the top of main content

I can make a Toggle ToC button next to the Toggle menu button or as a independent persistent button on the screen if that's needed.

Accessibility

ARIA attributes are added to all toggle buttons, and there's a new Skip to the Table of Contents button which automatically opens the panel (if hidden) and selects the first item in the ToC, if JavaScript is enabled.

For browsers with no JavaScript, toggle buttons to open the ToC panel on phones and small desktops should still work, although there would be no ARIA attribute updates, keyboard navigation (Skip to ToC link won't open the panel on phones and small desktops), and current section highlighting.

Keyboard navigation, I believe, is still somewhat limited. Feedback are welcome!

Breaking changes

IDs and classes that are affected by this change:

  • .visually-hidden
  • .__container
  • .side
  • .float
  • .__content
  • #__aside
  • #__aside-btn
  • .__aside-btn
  • .close-btn
  • .close-icon
  • .close-text
  • .arrow-down-icon
  • .toc-btn-sm
  • .toc-btn-sm-text
  • .current-heading
  • .toc-btn-md
  • .__page-actions
  • .aside-overlay

Discussions and help needed

  • For pages with no headings, the Table of Contents panel will still appear, albeit with only the heading title and no items in the list. It might be a good idea to hide the panel altogether, but there's no mechanism in place to detect such pages (ideally it should not rely on JavaScript and/or maintain compatibility with older browser versions, which has no support for :has)
  • Disabling the Table of Contents panel per page or layout currently leaves a blank placeholder. I intentionally did this to maintain the placement integrity of the sidebar, the main content and the ToC. Some may not like this behaviour nonetheless and rather want to expand $content-width to take up the remaining space of $toc-width

Feedback are also welcome on accessibility, ToC behaviour on mobile and replacing the panel with a custom implementation.

Special thanks and Acknowledgments

  • Material for MkDocs
  • Furo inspired by Just the Docs!, for their non-JS implementation of the ToC sidebar
  • GitBook for their ToC item highlighting behaviour, used as reference

@bmndc bmndc marked this pull request as ready for review March 20, 2025 05:05
@bmndc bmndc marked this pull request as draft August 4, 2025 04:31
@bmndc bmndc marked this pull request as ready for review August 4, 2025 07:27
@mattxwang
Copy link
Member

Just to chime in since I've had a bit of radio silence & I've noticed you've been keeping this PR up to date: this is awesome work and looks great! I would love to merge this in soon.

I have negative bandwidth now and would need to review this quite in-depth, both to evaluate the matrix of features you've added as well as doing an accessibility test. I want to do that relatively soon since this is such a great feature, but want to be transparent with my delays.

I hope to have some more time soon. Apologies for the delay!

@Sephoration
Copy link

“Absolutely love this branch! The way you implemented the TOC sidebar feels like watching a master carpenter fit the last dovetail—everything just slides into place. The opt-out logic is genius: instead of forcing the feature on every page, you trusted users to opt out when they need to, which is the perfect balance of power and politeness. And that media-query breakpoint tied to the sum of three variables? That’s not just responsive design, that’s responsive poetry. Thank you for making Jekyll feel like a first-class writing environment—this deserves to land in core!”

@Sephoration
Copy link

Will the main content be centered when the sidebar is closed? After all, there's an additional table of contents on the right.

@bmndc
Copy link
Author
bmndc commented Oct 27, 2025 via email

@Sephoration
Copy link

Hi there,
I just forked your project and everything runs perfectly—thank you for sharing it! I did notice two small console warnings: “Validate HTML (3.4)” and “Test CSS and JS (22.x)”. Could you kindly let me know if these appear on your side as well? I’d really appreciate any guidance you can offer.

@bmndc
Copy link
Author
bmndc commented Oct 29, 2025 via email

@lalithaar
Copy link

Gonna study the implementation later today, it's really clean :>

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

0