Skip to content

Attach sidebar-close handler to current-page links#1588

Open
jayaddison wants to merge 3 commits intoreadthedocs:masterfrom
jayaddison:issue-880/singlehtml-sidebar-css-selection
Open

Attach sidebar-close handler to current-page links#1588
jayaddison wants to merge 3 commits intoreadthedocs:masterfrom
jayaddison:issue-880/singlehtml-sidebar-css-selection

Conversation

@jayaddison
Copy link

This is intended primarily to resolve a problem with singlehtml documentation projects when viewed on narrow (typically mobile) displays.

Under those circumstances, the .current CSS selector does not match any sidebar menu elements, because there is no logical notion of a 'current' page in singlehtml -- every item is on the same page.

Therefore this change proposes an alternative way to identify sidebar links that are 'current' -- it checks for anchors that have an href beginning with the query-string fragment identifier (#).

This is intended to be compatible with both singlehtml and html project builds. It depends upon sphinx-doc/sphinx#12551

Resolves #880.

@jayaddison jayaddison requested a review from a team as a code owner August 12, 2024 11:59
@jayaddison

This comment was marked as resolved.

@jayaddison jayaddison marked this pull request as draft August 17, 2024 11:42
This is intended primarily to resolve a problem with `singlehtml`
documentation projects when viewed on narrow (typically mobile)
displays.

Under those circumstances, the `.current` CSS selector does not
match any sidebar menu elements, because there is no logical notion
of a 'current' page in `singlehtml` -- every item is on the same
page.

Therefore this change proposes an alternative way to identify sidebar
links that are 'current' -- it checks for anchors that have an `href`
beginning with the query-string fragment identifier (`#`).

This is intended to be compatible with both `singlehtml` and `html`
project builds.  It depends upon sphinx-doc/sphinx#12551
@jayaddison jayaddison force-pushed the issue-880/singlehtml-sidebar-css-selection branch from 2e97557 to 9d30f9e Compare October 15, 2024 11:23
@jayaddison
Copy link
Author

Rebased against sphinx_rtd_theme v3.0.1, and rebuilt the theme.js file since previous commit -- no changes.

Test results when self-building the sphinx_rtd_theme documentation (in this repo) using Sphinx v8.1.3:

Before (buggy)

buggy.mp4

After (fixed)

fixed.mp4

@jayaddison jayaddison marked this pull request as ready for review October 15, 2024 18:16
@jayaddison
Copy link
Author

Note: based on the dependency deprecation history for the project, I'd anticipate that the very earliest that this could be merged would likely be for a 4.0 release.

@jayaddison
Copy link
Author

I'm uncomfortable with the way that I offensively dismissed what I felt to be a spammy issue request about AI in an unrelated FOSS project thread yesterday (2026-02-14). I mention this in case you'd prefer not to accept my contributions; however you are still welcome to. I don't use AI myself and would like not to be critical of those who do, but I was angry.

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.

Navigation problems with singlehtml output

1 participant