Fix keyboard access for sidebar toggle - #3078
Open
lawrence3699 wants to merge 1 commit into
Open
lawrence3699 wants to merge 1 commit into
lawrence3699 wants to merge 1 commit into
Conversation
|
I'm going to test it this week. Thank you for making this documentation generator more accessible! |
|
If the fix doesn't touch the no-js version, should the toggle be un-hidden there so accessibility doesn't degrade without JS? |
| press-key: 'Enter' | ||
| wait-for-css-false: ("#mdbook-sidebar", {"display": "none"}) | ||
| // `transform` is 0.3s so we need to wait a bit (0.5s) to ensure the animation is done. | ||
| wait-for: 5000 |
Member
There was a problem hiding this comment.
You're waiting for 5K ms, so 5s, not 0.5s. ;)
| <label id="mdbook-sidebar-toggle-nojs" class="icon-button" for="mdbook-sidebar-toggle-anchor" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="mdbook-sidebar"> | ||
| {{fa "solid" "bars"}} | ||
| </label> | ||
| <button id="mdbook-sidebar-toggle" class="icon-button" type="button" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="mdbook-sidebar"> |
Member
There was a problem hiding this comment.
Instead of adding a whole new button, why not adding a new event handler in JS on the label so it works with Enter as well?
| html:not(.js) .left-buttons button { | ||
| display: none; | ||
| } | ||
| html.js #mdbook-sidebar-toggle-nojs { |
Member
There was a problem hiding this comment.
Please merge this rule with the one above. You can have multiple selectors separated with a comma.
GuillaumeGomez
requested changes
Aug 18, 2026
Collaborator
|
Reminder, once the PR becomes ready for a review, use |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2615.
The sidebar toggle was rendered as a label for the hidden checkbox. Unlike the neighboring theme and search controls, it could not receive focus as a button, and pressing Enter did not toggle the sidebar.
This keeps the checkbox/label path for no-JavaScript output, but renders the JavaScript-enabled control as a native button. The button toggles the same checkbox and dispatches its existing change handler, so the current sidebar state, ARIA updates, and localStorage behavior stay on the existing path.
The GUI regression focuses the toggle directly because Tab traversal was not reliable in the headless test harness; it verifies the control can receive focus and that Enter toggles the sidebar closed and open.
Validation:
cargo test --test gui -- sidebar.gomlcargo test --test gui -- sidebar-nojs.gomlnpm run lintgit diff --check