Skip to content

A11Y: SVG icons should be hidden unless a label is provided #33059

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 4, 2025

Conversation

awesomerobot
Copy link
Member

@awesomerobot awesomerobot commented Jun 3, 2025

This is fairly minor because usually SVGs aren't focusable, but this adds aria-hidden='true' to all SVGs by default unless either an aria-label or label is provided. This gets reported to us in automated tests from time to time.

So now:

  1. SVG: aria-hidden="true" (new behavior, safe default when no label is provided)
  2. SVG with label param: aria-hidden="true" and sr-only label is provided
  3. SVG with aria-label param: aria-hidden="false" and aria-label is provided

@tgxworld tgxworld requested a review from Copilot June 4, 2025 01:01
Copy link
Contributor

@Copilot 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

This PR implements accessibility improvements for SVG icons by ensuring they are hidden by default unless an accessible label is provided. It updates unit tests to match the new markup and modifies the icon rendering logic in the library to reflect the new aria attribute behavior.

Reviewed Changes

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

File Description
plugins/discourse-local-dates/test/javascripts/unit/local-date-builder-test.js Updated expected HTML output to include aria-hidden attribute
app/assets/javascripts/discourse/tests/integration/helpers/d-icon-test.gjs Updated expected HTML output for SVG icons with aria-hidden attribute
app/assets/javascripts/discourse/app/lib/icon-library.js Adjusted SVG rendering logic to conditionally set aria attributes based on provided parameters

@@ -156,12 +156,10 @@ registerIconRenderer({
const id = escape(handleIconId(icon));
let html = `<svg class='${escape(iconClasses(icon, params))} svg-string'`;

Copy link
Preview

Copilot AI Jun 4, 2025

Choose a reason for hiding this comment

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

The change prioritizes 'aria-label' over 'label' for setting aria attributes. Consider adding a comment to clarify that this behavior aligns with the intended A11Y guidelines where an explicit 'aria-label' takes precedence, while a 'label' is handled separately for providing visible descriptions.

Suggested change
// Prioritize 'aria-label' over 'label' for setting ARIA attributes.
// This aligns with A11Y guidelines where 'aria-label' provides an explicit
// programmatically accessible name, while 'label' is used for visible descriptions.

Copilot uses AI. Check for mistakes.

@awesomerobot awesomerobot merged commit f663393 into main Jun 4, 2025
17 checks passed
@awesomerobot awesomerobot deleted the a11y-svg-hidden branch June 4, 2025 12:21
martin-brennan pushed a commit that referenced this pull request Jun 10, 2025
This is fairly minor because usually SVGs aren't focusable, but this
adds `aria-hidden='true'` to all SVGs by default unless either an
`aria-label` or `label` is provided. This gets reported to us in
automated tests from time to time.

So now:

1. SVG: `aria-hidden="true"` (new behavior, safe default when no label
is provided)
2. SVG with `label` param: `aria-hidden="true"` and `sr-only` label is
provided
3. SVG with `aria-label` param: `aria-hidden="false"` and `aria-label`
is provided
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants