Skip to content

Keep focus on sidebar links after navigation#2740

Open
puneetdixit200 wants to merge 1 commit into
docsifyjs:developfrom
puneetdixit200:fix-sidebar-navigation-focus
Open

Keep focus on sidebar links after navigation#2740
puneetdixit200 wants to merge 1 commit into
docsifyjs:developfrom
puneetdixit200:fix-sidebar-navigation-focus

Conversation

@puneetdixit200
Copy link
Copy Markdown

Summary

Keeps keyboard focus on the activated sidebar link after Docsify finishes rendering the destination route.

For hash-mode navigation, the router now carries the original link click event through the hashchange callback. The event layer uses that clicked sidebar link to focus the matching link in the freshly rendered sidebar instead of moving focus to the main heading, whose programmatic focus is intentionally visually hidden.

Related issue, if any:

Fixes #2600

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

For any code change,

  • Related documentation has been updated, if needed
  • Related tests have been added or updated, if needed

Does this PR introduce a breaking change?

  • Yes
  • No

Tested in the following browsers:

  • Chrome
  • Firefox
  • Safari
  • Edge

Verification run:

  • npm run build
  • npx playwright test test/e2e/sidebar.test.js --project=chromium
  • npm run test:unit
  • npm run lint
  • git diff --check

@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 4, 2026

Someone is attempting to deploy a commit to the Docsify Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docsify-preview Ready Ready Preview, Comment Jun 5, 2026 3:55am

Copy link
Copy Markdown
Member

@paulhibbitts paulhibbitts left a comment

Choose a reason for hiding this comment

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

Thanks very much for this helpful PR @puneetdixit200 !

My knowledge of accessibility is quite basic - I used the following steps to test your PR:

  1. Open PR preview
  2. Use the TAB key to step through elements of the user interface, stoping on a navigation item in the Sidebar
  3. Use the RETURN key to activate selected link and display relevant content
  4. Using the TAB key stop on a second navigation item in the Sidebar
  5. Use the RETURN key to activate the second selected link and display relevant content

Doing the above I see that the selected Sidebar item keeps focus - please confirm this is a valid test of the changes you submitted. Thanks again, Paul.

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.

Keyboard focus is getting lost after activating home control in left navigation pane in windows.

2 participants