Skip to content

fix(docs): add aria-label to Expressive Code copy-to-clipboard buttons#24099

Merged
pelikhan merged 2 commits intomainfrom
copilot/fix-rss-feed-return-404
Apr 2, 2026
Merged

fix(docs): add aria-label to Expressive Code copy-to-clipboard buttons#24099
pelikhan merged 2 commits intomainfrom
copilot/fix-rss-feed-return-404

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 2, 2026

Expressive Code renders copy buttons with title="Copy to clipboard" but no aria-label, leaving them without an accessible name for screen readers (WCAG 2.1 SC 4.1.2).

Changes

  • docs/src/scripts/copy-button-aria.ts — new script that selects .expressive-code button[title]:not([aria-label]) and mirrors titlearia-label; re-runs on astro:page-load for client-side navigation
  • docs/src/components/CustomHead.astro — imports the new script alongside the existing search-aria.ts and responsive-tables.ts enhancements

Follows the established pattern for DOM-based accessibility patches in this project. Only sets aria-label on buttons that don't already have one — no visual change.

Expressive Code renders copy buttons with `title` but no `aria-label`,
so they lack an accessible name for screen readers (WCAG 2.1 SC 4.1.2).

Add copy-button-aria.ts script that mirrors `title` → `aria-label` on
`.expressive-code button[title]:not([aria-label])` elements, following
the same pattern as the existing search-aria.ts enhancement.

Resolves warning #3 from the multi-device docs testing report.

Agent-Logs-Url: https://github.com/github/gh-aw/sessions/afbccc07-e106-4294-af54-242e4af333b2

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix RSS feed returning 404 in dev server fix(docs): add aria-label to Expressive Code copy-to-clipboard buttons Apr 2, 2026
Copilot AI requested a review from pelikhan April 2, 2026 12:42
@pelikhan pelikhan marked this pull request as ready for review April 2, 2026 12:45
Copilot AI review requested due to automatic review settings April 2, 2026 12:45
@pelikhan pelikhan merged commit 6ea0a07 into main Apr 2, 2026
1 check passed
@pelikhan pelikhan deleted the copilot/fix-rss-feed-return-404 branch April 2, 2026 12:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds an accessibility patch so Expressive Code’s copy-to-clipboard buttons receive an accessible name by mirroring their existing title attribute into aria-label when missing, including on Astro client-side navigation.

Changes:

  • Add a new DOM enhancement script to set aria-label on .expressive-code buttons based on title.
  • Load the new script from CustomHead.astro alongside existing accessibility/enhancement scripts.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
docs/src/scripts/copy-button-aria.ts New client-side enhancement that mirrors titlearia-label for copy buttons and re-applies on astro:page-load.
docs/src/components/CustomHead.astro Imports the new script so it runs site-wide.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +22 to +38
const buttons = document.querySelectorAll<HTMLButtonElement>(
'.expressive-code button[title]:not([aria-label])',
);

buttons.forEach((button) => {
const label = button.getAttribute('title');
if (label) {
button.setAttribute('aria-label', label);
}
});
}

// Run on initial page load
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', enhanceCopyButtons);
} else {
enhanceCopyButtons();
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

This new script is indented with tabs (e.g. in the querySelectorAll / forEach block). The other docs enhancement scripts use 2-space indentation (see docs/src/scripts/responsive-tables.ts and search-aria.ts), and the repo’s Prettier config is set for 2-space formatting. Reformat this file to match the established style (run Prettier or convert tabs to spaces) to avoid inconsistent diffs and formatter churn.

Suggested change
const buttons = document.querySelectorAll<HTMLButtonElement>(
'.expressive-code button[title]:not([aria-label])',
);
buttons.forEach((button) => {
const label = button.getAttribute('title');
if (label) {
button.setAttribute('aria-label', label);
}
});
}
// Run on initial page load
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', enhanceCopyButtons);
} else {
enhanceCopyButtons();
const buttons = document.querySelectorAll<HTMLButtonElement>(
'.expressive-code button[title]:not([aria-label])',
);
buttons.forEach((button) => {
const label = button.getAttribute('title');
if (label) {
button.setAttribute('aria-label', label);
}
});
}
// Run on initial page load
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', enhanceCopyButtons);
} else {
enhanceCopyButtons();

Copilot uses AI. Check for mistakes.
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.

🔍 Multi-Device Docs Testing Report - 2026-04-02

3 participants