You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When keyboard or screen-reader users clicked Table of Contents (TOC) anchor links in the sidebar, keyboard focus remained stuck on the sidebar link or was lost.
This PR:
Adds an onClick handler to TOC NavLink items in SidebarItem.jsx that finds the target heading (accounting for inner anchor spans), sets tabindex="-1" if necessary, and programmatically shifts focus to the heading.
Adds visible focus outline styling for headings in Markdown.css.
Adds unit tests in SidebarItem.test.jsx covering focus behavior, inner span targets, modifier keys, non-existent targets, and same-hash clicks.
Testing
Verified with Jest unit tests (SidebarItem.test.jsx - 12 passed)
Code formatted and verified with Prettier and ESLint
Summary by CodeRabbit
Accessibility
Markdown headings display a visible focus outline, with colors adapted for dark mode.
Following a sidebar link to a section moves keyboard focus to its heading, or to the target when no heading is available.
When a section appears after content loads, it scrolls into view and receives focus unless you have moved focus elsewhere.
Selecting a link for the section already in view scrolls to that section and focuses it.
Modified clicks, links to other pages, and links without a matching target retain their existing behavior.
No actionable comments were generated in the recent review.
Walkthrough
Page hash navigation and sidebar TOC anchor clicks now focus the target heading after 100 ms. The code adds tabindex="-1" when needed. Page navigation cancels pending focus during cleanup and skips focus if focus moves elsewhere. Sidebar focus handling ignores modified clicks, cross-page links, and missing targets. Same-hash clicks scroll the target into view. Markdown headings receive visible focus outlines, with a separate color in dark mode. Tests cover these behaviors.
Severity of issue fixed: Medium
Merge Risk: Minimal · up to 55cb5
This change moves keyboard focus to the target heading after sidebar table-of-contents navigation and adds visible focus outlines. No concrete merge-blocking risk remains in the reviewed changes. One minor edge case is left: a focus change made within 100 ms of a same-page link click can be overridden.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the SidebarItem component and the keyboard focus management on TOC anchor navigation. The changeset adds an anchor click handler in SidebarItem.jsx that focuses the target heading, upd…
Linked Issues check
Directly linked issue #8458 has three coding requirements: (1) make heading anchor targets focusable, (2) add an onClick handler to TOC NavLinks that finds the target by ID and calls focus() after a s…
Out of Scope Changes check
All changed files serve the #8458 focus objective. SidebarItem.jsx adds the TOC click handler. Markdown.css adds visible heading focus feedback. Page.jsx adds focus after hash navigation, which covers…
Full details: Title check
Explanation
The title names the SidebarItem component and the keyboard focus management on TOC anchor navigation. The changeset adds an anchor click handler in SidebarItem.jsx that focuses the target heading, updates Page.jsx to focus hash targets, and adds focus outline styles in Markdown.css. The title matches the main change. It omits the Page and CSS changes, which is acceptable. The title follows the conventional commit style and is specific. The title's PR number (#8458) differs from the PR objectives' number (#8475), but this does not affect the title's relevance to the changeset.
Full details: Linked Issues check
Explanation
Directly linked issue #8458 has three coding requirements: (1) make heading anchor targets focusable, (2) add an onClick handler to TOC NavLinks that finds the target by ID and calls focus() after a short timeout, and (3) keep a visible focus outline on headings. Verified in the whole-PR diff (mergeBase to head): SidebarItem.jsx adds handleAnchorClick, passed as onClick to the Anchors NavLink. It resolves the target with document.getElementById, uses closest("h1, ... h6") to handle inner anchor spans, sets tabindex="-1" when absent, and calls heading.focus() after 100 ms. Modified clicks, missing IDs, and cross-page links return early. Markdown.css adds a :focus outline (2px, 2px offset) on h1 to h6, with a dark-mode color override. Requirement (1) and (2) are met. Requirement (3) is met by the CSS. Page.jsx adds the same focus logic for hash navigation on load and for dynamic content. I read the SidebarItem.jsx and Markdown.css diffs directly. I did not read the test files or Page.jsx in this pass. The test coverage claims rely on the change summary, not on direct test reads. No non-coding requirement applies.
Full details: Out of Scope Changes check
Explanation
All changed files serve the #8458 focus objective. SidebarItem.jsx adds the TOC click handler. Markdown.css adds visible heading focus feedback. Page.jsx adds focus after hash navigation, which covers cross-page TOC links and dynamically loaded content. It applies to any hash load, which is wider than sidebar clicks, but it addresses the same focus loss. The PR description does not mention Page.jsx. This is a documentation gap, not a scope violation. The test files support the listed behaviors. The Page.jsx and test-file conclusions rely on the change summary, not on direct reads in this pass. Minor note: the 100 ms timeout in handleAnchorClick is not cleared on unmount, which does not affect scope.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 295a7540-7a6b-48ee-9b2a-47acd6423692
Commits
Reviewing files that changed from the base of the PR and between c6fd65f and 55cb59d.
Files selected for processing: 2
src/components/Markdown/Markdown.css
src/components/Page/Page.jsx
Files skipped from review as they are similar to previous changes: 1
src/components/Markdown/Markdown.css
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 50140316-0eb0-4fb7-ad6d-7cd4cca66486
Commits
Reviewing files that changed from the base of the PR and between a1b4b8d and 69a63a4.
Files selected for processing: 3
src/components/Markdown/Markdown.css
src/components/SidebarItem/SidebarItem.jsx
src/components/SidebarItem/SidebarItem.test.jsx
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Major · Functional Correctness · Heavy lift
Supported by static analysis
Script executed:
sed -n 1,140p src/components/SidebarItem/SidebarItem.jsx
sed -n 1,200p src/components/Sidebar/Sidebar.jsx
Repository: webpack/webpack.js.org
Length of output: 7964
Script executed:
nl -ba src/components/SidebarItem/SidebarItem.jsx | sed -n '1,220p'
nl -ba src/components/Sidebar/Sidebar.jsx | sed -n '1,150p'
Repository: webpack/webpack.js.org
Length of output: 10737
Focus cross-page anchors after the destination renders.
Sidebar renders SidebarItem for every page, and SidebarItem renders each page’s anchor NavLink. For an anchor on another page, handleAnchorClick calls document.getElementById(anchorId) before navigation. The destination heading is therefore unavailable unless the current page contains the same ID. Move cross-page focus handling to the destination page after its content renders.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: c9a4b685-c744-47de-8931-bc78408a40cb
Commits
Reviewing files that changed from the base of the PR and between 69a63a4 and 5809009.
Files selected for processing: 4
src/components/Page/Page.jsx
src/components/Page/__tests__/Page.test.jsx
src/components/SidebarItem/SidebarItem.jsx
src/components/SidebarItem/SidebarItem.test.jsx
Files skipped from review as they are similar to previous changes: 2
src/components/SidebarItem/SidebarItem.jsx
src/components/SidebarItem/SidebarItem.test.jsx
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
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
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.
Description
Fixes #8458.
When keyboard or screen-reader users clicked Table of Contents (TOC) anchor links in the sidebar, keyboard focus remained stuck on the sidebar link or was lost.
This PR:
onClickhandler to TOCNavLinkitems inSidebarItem.jsxthat finds the target heading (accounting for inner anchor spans), setstabindex="-1"if necessary, and programmatically shifts focus to the heading.Markdown.css.SidebarItem.test.jsxcovering focus behavior, inner span targets, modifier keys, non-existent targets, and same-hash clicks.Testing
SidebarItem.test.jsx- 12 passed)Summary by CodeRabbit