Skip to content

fix(docs): make code blocks reachable and readable by keyboard and screen reader - #49562

Merged
czenko merged 1 commit into
masterfrom
docs/codeblock-keyboard-and-screen-reader
Aug 26, 2026
Merged

czenko merged 1 commit into
masterfrom
docs/codeblock-keyboard-and-screen-reader

Conversation

@czenko

@czenko czenko commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Closes DOCS-1283

CleanShot.2026-08-25.at.15.14.53.mp4

Problem

Three defects in the docs code block:

  • The scroll container has no tabindex. On /guides/database/tables, 18 blocks, none focusable, 2 overflowing at 1280px. Tab skips the scroll region, so a keyboard-only user cannot scroll code that runs off the edge.
  • The container has role="group" with no accessible name, so it announces as bare "group".
  • The line-number gutter has no aria-hidden, so digits are read inline with the code. A block linearizes as 1import { createClient } from '@supabase/supabase-js'23const supabase = ..., with lines 2 and 3 collapsing into "23".

Four more surfaced while testing the fix:

  • The wrap and copy buttons were absolutely positioned inside the element that scrolls, so right-2 measured against the scrollable content box. Scrolling dragged them out of the corner into the middle of the code. This one predates the PR.
  • The buttons preceded the code in the DOM, so a screen reader read two actions before naming what they act on.
  • focus-within only fired for the buttons, so focusing the block left the controls invisible.
  • Both buttons set an aria-label identical to their tooltip text, and Radix points aria-describedby at the tooltip on focus, producing "Copy code, button, Copy code".

Solution

Keyboard:

  • Split the scroll region out of the positioning container, so the controls stay pinned.
  • Give the scroll region a tabIndex and a focus ring.
  • Reveal the controls on group-focus-within.

Screen reader:

  • Name the region <language>, <n> lines. Code content stays readable; the summary goes in the name so the group can be skipped or stepped into.
  • Map fence aliases to spoken names, so ts announces as TypeScript. Only the ambiguous ones; bash, python, kotlin, dart, swift already read fine.
  • aria-hidden the gutter. The numbers are already select-none, and copy takes its content from the source string rather than the DOM, so copy behavior is unchanged.
  • Order the controls after the code.
  • Announce the word wrap toggle through a live region, matching the copy button.
  • Opt both buttons out of Radix's generated description.

Also moved the data-wrapped side effect out of the setIsWrapped updater, since React calls updaters twice under StrictMode.

Manual testing

  1. Open /docs/guides/database/tables.
  2. Run document.querySelectorAll('.code-scroll[tabindex="0"]').length in the console. Expect 18.
  3. Run [...document.querySelectorAll('.code-scroll')].map(b => b.getAttribute('aria-label')). Expect entries like SQL, 11 lines and bash, 2 lines, plus one bare 2 lines for the fence with no language.
  4. Tab to a code block. Expect a visible focus ring, and the wrap and copy buttons to appear.
  5. Press ArrowRight on the block under "Basic data loading", which overflows. Expect it to scroll, and the buttons to stay in the top-right corner.
  6. Press Enter on the wrap button. Expect the code to wrap and a screen reader to announce "Word wrap enabled".
  7. With VoiceOver on, focus a code block. Expect "SQL, 11 lines, code block", then the code read without line numbers interleaved. Focus each button and expect its name once, not twice.

Summary by CodeRabbit

  • Accessibility

    • Improved code block labels for screen readers, including programming language and line count.
    • Added announcements when word wrap is enabled or disabled.
    • Enhanced keyboard focus behavior for code block controls.
  • Usability

    • Kept code block controls visible while scrolling through code.
    • Improved wrapped-code overflow handling.
    • Removed redundant tooltip descriptions for copy and word-wrap controls.

@vercel

vercel Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, v0 Aug 25, 2026 10:34pm
6 Skipped Deployments
Project Deployment Actions Updated (UTC)
studio Ignored Ignored Aug 25, 2026 10:34pm
design-system Skipped Skipped Aug 25, 2026 10:34pm
studio-self-hosted Skipped Skipped Aug 25, 2026 10:34pm
studio-staging Skipped Skipped Aug 25, 2026 10:34pm
ui-library Skipped Skipped Aug 25, 2026 10:34pm
zone-www-dot-com Skipped Skipped Aug 25, 2026 10:34pm

Request Review

@coderabbitai

coderabbitai Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 83643e16-60cd-4c64-b899-be6a0e586a06

📥 Commits

Reviewing files that changed from the base of the PR and between 6ea3567 and 972b0b0.

📒 Files selected for processing (4)
  • apps/docs/features/ui/CodeBlock/CodeBlock.client.tsx
  • apps/docs/features/ui/CodeBlock/CodeBlock.tsx
  • apps/docs/features/ui/CodeBlock/CodeBlock.utils.ts
  • apps/docs/styles/globals.css

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

Code blocks now use accessible language and line-count labels, a focusable scroll container, pinned controls, live wrap-state announcements, and updated wrapped-code overflow styling.

Changes

Code block accessibility

Layer / File(s) Summary
Accessible code block structure
apps/docs/features/ui/CodeBlock/CodeBlock.tsx, apps/docs/features/ui/CodeBlock/CodeBlock.utils.ts
Code blocks use generated accessible labels and a focusable scroll container. Controls render outside the scroller. Supporting comments were simplified.
Wrap controls and announcements
apps/docs/features/ui/CodeBlock/CodeBlock.client.tsx
Wrap changes announce the new state. Controls appear when the control group receives focus. Redundant tooltip descriptions are suppressed.
Wrapped-code overflow styling
apps/docs/styles/globals.css
Wrapped-code overflow now targets the nested .code-scroll container.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 972b0

This localized documentation accessibility change is merge-ready after normal checks and review; no actionable merge-blocking risk remains.

Suggested reviewers: awaseem

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 3 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main accessibility improvements for documentation code blocks.
Description check ✅ Passed The description explains the defects, solution, issue reference, and manual testing results. It does not include the required CONTRIBUTING.md acknowledgment or the template headings, but it provides t…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the defects, solution, issue reference, and manual testing results. It does not include the required CONTRIBUTING.md acknowledgment or the template headings, but it provides the required change context in equivalent sections.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 3 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch docs/codeblock-keyboard-and-screen-reader

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Aug 25, 2026
@czenko
czenko force-pushed the docs/codeblock-keyboard-and-screen-reader branch from eb47238 to ef8b856 Compare August 25, 2026 22:15
…reen reader

The code block scroll container had no tabindex, so a keyboard-only user could
not reach it to scroll code that runs off the edge. Two further defects turned
up alongside it. axe reports zero violations here both before and after, so none
of this was caught by the automated suite.

Keyboard:

- Split the scroll region out of the positioning container. The controls were
  absolutely positioned inside the element that scrolls, so `right-2` measured
  against the scrollable content box and dragged them out of the corner.
- Give the scroll region a tabindex and a focus ring.
- Reveal the controls on group-focus-within, so focusing the block shows them
  instead of waiting for a button to take focus.

Screen reader:

- Name the region "<language>, <n> lines", so a summary is announced on arrival
  and the group can be skipped or stepped into. Fence aliases map to spoken
  names, so `ts` announces as TypeScript rather than "tee ess".
- aria-hidden the line-number gutter. A block linearized as "1import
  { createClient } from '@supabase/supabase-js'23const supabase = ...", with
  lines 2 and 3 collapsing into "23".
- Order the controls after the code, so the block is named before its actions.
- Announce the word wrap toggle through a live region, matching the copy button.
- Opt both buttons out of Radix's generated description, which repeated the
  accessible name as "Copy code, button, Copy code".

Also move the data-wrapped side effect out of the setIsWrapped updater, since
React calls updaters twice under StrictMode.
@czenko
czenko marked this pull request as ready for review August 25, 2026 22:29
@czenko
czenko requested a review from a team as a code owner August 25, 2026 22:29
@czenko
czenko force-pushed the docs/codeblock-keyboard-and-screen-reader branch from 1aeea7f to 972b0b0 Compare August 25, 2026 22:29

@dnywh dnywh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tested as per instructions. Approving despite VoiceOver not announcing the full code block contents, as discussed elsewhere.

@czenko
czenko merged commit f09d35c into master Aug 26, 2026
39 checks passed
@czenko
czenko deleted the docs/codeblock-keyboard-and-screen-reader branch August 26, 2026 17:43
hunleyd added a commit that referenced this pull request Aug 26, 2026
…for-pitr-archiving-stale

* origin/master: (26 commits)
  chore(docs): add Simon Tomlinson to humans.txt (#49547)
  fix(docs): make code blocks reachable and readable by keyboard and screen reader (#49562)
  feat: update mgmt api docs (#49128)
  fix: display request body Array<object> schema/fields in Management API Reference (#49575)
  Set up feature preview for explorer (#49602)
  docs(troubleshooting): add postgres_changes not delivering guide (#48997)
  chore: Update API types (#49598)
  refactor(studio): fetch MCP tool→FGA map from mgmt-api endpoint (#49225)
  Add go page: Postgres Summit US 2026 contest (#49597)
  Add Lingo.dev customer case study (#49595)
  fix(studio): hide legacy API keys on High Availability projects (#49552)
  [FE-4246] fix(studio): resolve notebook database labels (#49554)
  fix(studio): resolve dirty notebook save conflicts (#49540)
  fix(studio): make menu links reliable (#49584)
  [FE-3717] feat(studio): Multigres cluster topology diagram (#49298)
  feat(www): homepage json-ld, canonical, 404 links (#49533)
  refine role impersonation popover (#49467)
  feat(studio): move read replica creation to a dialog (#49516)
  fix(www): pricing table spacing and sticky offset (#49532)
  fix(studio): treat region flags as decorative by default (#49574)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants