A11y: Fix MDX heading anchors not keyboard accessible#34368
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughRefactors the MDX heading copy-link to a Button-wrapped anchor, makes the octicon visible on both :hover and :focus-within, and updates the click handler to call preventDefault(), verify the target element exists, then invoke navigate(context, hash). ChangesMDX Heading Anchor
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
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. Comment |
|
Synced the branch with the latest next — no conflicts, mdx.tsx wasn't touched upstream. |
308b110 to
7173d68
Compare
Sidnioulz
left a comment
There was a problem hiding this comment.
LGTM overall. Waiting for the Chromatic UI Test to finish before I approve :)
|
Pulled the commit and ran yarn task compile -s compile — compiles clean, no issues. |
Sidnioulz
left a comment
There was a problem hiding this comment.
@TheSeydiCharyyev if you look at the UI Tests, you'll see there's a layout shift for titles. They have all moved to the right.
Could you please find a way to make sure there is no visual change for titles? Thanks.
You can ignore the failed Linux test, it's a flake. It should go away the next time CI runs.
|
Fixed — the anchor was floated, and the Button's padding widened it, which pushed the heading text to the right. It's now positioned absolutely in the left gutter, so the Button's dimensions no longer affect heading layout. Verified locally on an MDX page with headings — titles are flush-left with body text again. |
Description
Makes MDX heading anchors keyboard accessible by replacing the inaccessible styled anchor with a Button component.
Related Issue
Fixes #33240
Changes Made
styled.a(OcticonAnchor) withButton asChildwrapping an<a>element for consistent styling and built-in accessibilityaria-hidden="true"andtabIndex={-1}so the anchor is reachable by keyboard and screen readersariaLabel="Copy heading URL to address bar"which also provides an automatic tooltip on hover/focus&:focus-within svgstyle to show the link icon on keyboard focus (alongside existing:hover)<a>withhrefso tocbot Table of Contents continues to workHow it works
Button asChilduses Radix Slot to render an<a>element with button styles — visually a button, semantically a linkariaLabelon Button automatically creates a tooltip viaInteractiveTooltipWrapper:focus-withinon the heading container makes the SVG icon visible when the anchor inside receives keyboard focusManual testing
Checklist
Summary by CodeRabbit
New Features
Bug Fixes