Conversation
There was a problem hiding this comment.
The code is technically clean and does as the PR description states.
I'm less convinced of the actual accessibility of such an approach :)
For instance, if I have a breadcrumb that starts with the "house" icon to bring you back to the home page… I'm not sure that a screenreader reading "HOUSE" aloud is really going to be easily understood by a person with sight impairments.
Or another one, if you have a "3-lines" icon for hamburger icon toggle for the nav on mobile, while the screenreader reading this aloud be enough to convey what the button does?
We'd be fully dependent on a developer having chosen expressive icon names to convey the right message in the given context… I feel this is a bit of a stretch.
I would be tempted to let those continue failing in the audit to force website developers to use meaningful alt names instead. Defaulting to the "alt" which would potentially be empty, is good enough in my opinion. If they did the effort to specify a decent alt text, they are good to go… if they didn't, then the a11y audits will remind them.
Description
This PR adds automatic
aria-labelattributes to icon-only links to fix Lighthouse accessibility errors ("Links do not have a discernible name"). WhendecorateIcon()processes an icon inside a link, it now:aria-labeldoesn't already existaria-labelto the icon's alt text (if provided) or icon name as fallbackRelated Issue
Fixes #13
Motivation and Context
When authors create links using only SVG icons (common for brand logos, social icons, navigation), the resulting HTML has no accessible name for screen readers. This causes Lighthouse to flag these as accessibility violations, reducing scores unnecessarily.
The previous attempt (PR #14) was closed, but the underlying issue remained unresolved. This implementation takes a more conservative approach by only adding labels to icon-only links rather than all linked icons.
How Has This Been Tested?
Added comprehensive test coverage in
test/decorate/decorateIcon.test.html:aria-labelis added using icon nameFuture Considerations
Should this be extracted to a more general link accessibility function?
Currently, this logic lives in
decorateIcon()because:However, there could be value in a broader
decorateLinks()function that:Types of changes
Checklist: