Skip to content

fix(markdown): add accessible grouping to code groups - #5531

Open
parnilV06 wants to merge 1 commit into
vuejs:mainfrom
parnilV06:fix/code-group-a11y
Open

parnilV06 wants to merge 1 commit into
vuejs:mainfrom
parnilV06:fix/code-group-a11y

Conversation

@parnilV06

Copy link
Copy Markdown

Description

VitePress code groups use native radio inputs and associated labels to display alternative code snippets in a tabbed interface. However, the generated .tabs wrapper is a generic <div> without explicit radio-group semantics or an accessible name.

This can prevent assistive technologies from identifying the relationship between the radio options and can trigger accessibility findings related to WCAG 2.1 Success Criterion 1.3.1 (Info and Relationships).

This PR adds role="radiogroup" and aria-label="Code group" to the existing .tabs element. The change provides explicit grouping semantics and an accessible name while preserving the existing DOM hierarchy, radio inputs, labels, checked state, tab-switching behavior, and code panels.

Changes made:

  • Added role="radiogroup" to the code-group tabs wrapper.
  • Added aria-label="Code group" to give the radio group an accessible name.
  • Updated the existing code-group unit test and inline snapshot to verify the new attributes and preserve the existing markup.

The change is intentionally limited to the accessibility issue. It introduces no new Markdown syntax and requires no changes to client-side tab-switching logic or theme CSS.

Validation performed:

  • Focused code-group tests: 38 passed.
  • Full unit test suite: 517 tests passed across 32 test files.
  • pnpm typecheck: passed.
  • pnpm format:fail: passed.
  • git diff --check: passed.

Linked Issues

Closes #5530

Additional Context

The implementation keeps the radio controls inside the existing .tabs wrapper and leaves the .blocks container outside the radio group's semantic boundary. This avoids restructuring the DOM and preserves compatibility with the existing tab-switching implementation.

The updated regression test checks the accessible role and name, and the snapshot verifies that the existing radio inputs, associated labels, checked state, and code panels remain intact.

Please review whether the default accessible name, Code group, is appropriate for VitePress's code-group component. Custom group naming and localization are intentionally outside the scope of this PR.

Live screen-reader testing and a separate end-to-end accessibility audit have not yet been performed.

Copilot AI balanced review requested due to automatic review settings October 13, 2026 05:54

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@parnilV06

Copy link
Copy Markdown
Author

/agentic_review

This branch has not been deployed

No deployments
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.

Add semantic grouping and accessible names to code groups

2 participants