Skip to content

Fix keyboard access for sidebar toggle - #3078

Open
lawrence3699 wants to merge 1 commit into
rust-lang:mainfrom
lawrence3699:fix/sidebar-toggle-keyboard
Open

lawrence3699 wants to merge 1 commit into
rust-lang:mainfrom
lawrence3699:fix/sidebar-toggle-keyboard

Conversation

@lawrence3699

Copy link
Copy Markdown

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.goml
  • cargo test --test gui -- sidebar-nojs.goml
  • npm run lint
  • git diff --check

@rustbot rustbot added the S-waiting-on-review Status: waiting on a review label Apr 27, 2026
@ShamrockLee

Copy link
Copy Markdown

I'm going to test it this week. Thank you for making this documentation generator more accessible!

@Omnikron13

Copy link
Copy Markdown

If the fix doesn't touch the no-js version, should the toggle be un-hidden there so accessibility doesn't degrade without JS?

Comment thread tests/gui/sidebar.goml
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

@GuillaumeGomez GuillaumeGomez Aug 18, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're waiting for 5K ms, so 5s, not 0.5s. ;)

View changes since the review

<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">

@GuillaumeGomez GuillaumeGomez Aug 18, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

View changes since the review

html:not(.js) .left-buttons button {
display: none;
}
html.js #mdbook-sidebar-toggle-nojs {

@GuillaumeGomez GuillaumeGomez Aug 18, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please merge this rule with the one above. You can have multiple selectors separated with a comma.

View changes since the review

@GuillaumeGomez GuillaumeGomez left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some changes to be done but looks like a good start!

View changes since this review

@rustbot rustbot added S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. and removed S-waiting-on-review Status: waiting on a review labels Aug 18, 2026
@rustbot

rustbot commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

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

Labels

S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Accessibility: "Toggle Table of Content" hamburger menu is not keyboard focusable

5 participants