svg-inline-loader
svg-inline-loader copied to clipboard
Apply idPrefix to references in aria-labelledby
To make svgs more accessible to people with screen readers, we can make use of a few elements and attributes:
-
<title>
to set a title for the image -
<desc>
to describe the image -
@aria-labelledby
to tell screen readers where the title and description are located in the tree
Here's some more info on how to best use them: https://css-tricks.com/accessible-svgs/#article-header-id-6
We're using svg-inline-loader over at brigade.com to make sure every svg has unique ids, but after adding accessibility markup we noticed that the references weren't right:
<svg viewBox="0 0 24 24" role="img" aria-labelledby="shareIconTitle shareIconDesc">
(I've manually removed some stuff from the above svg to make it shorter).
Notice how the references in aria-labelledby are now referencing missing ids. To fix this, we can apply the prefix here as well.
Apart from the above fix, I modified an assertion made in tests to be more robust.
Test failures seem unrelated to my changes (they work locally).