question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

put role="img", if missing, to produced svg element

See original GitHub issue

šŸš€ Feature Proposal

Consider setting role="img" to <svg>.

Motivation

Because out-of-the-box, Illustrator and many others donā€™t add it, and developers have to do it manually.

Example

Putting role=ā€œimgā€ on the svg element ensures it is identified as a graphic.

https://www.tpgi.com/using-aria-enhance-svg-accessibility/

Pitch

Why does this feature belong in the SVGR ecosystem? Itā€™s a no-brainer, a quick improvement to accessibility.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
pachukacommented, Oct 3, 2022

Not a huge fan of this being defaulted in the way it is. While I appreciate the sentiment this is problematic since now this requires alt text or a role=ā€œpresentationalā€ override on every SVG (to my understanding, I could be wrong that a label would be required now - https://dequeuniversity.com/rules/axe/4.4/svg-img-alt?application=axeAPI). Most of our usages of SVGs are for icons used in buttons that already configured for accessibility and the SVG doesnā€™t need to be focusable or explained to the non visual user.

It would at the least be nice if we could opt-out of this default behavior, I noticed we do parse the svgProps but since thatā€™s a spread/merge it wont override if we set role to undefined to attempt to unset it.

image

While not breaking code-wise, this feels like a breaking change in terms of behavior.

5reactions
pzicommented, Oct 4, 2022

I agree with @pachuka, it wouldā€™ve been nice to be able to opt-out of this behaviour. Our use-case is the same and the vast majority of SVGs used in our project are icons or presentational only. Could almost argue that all SVG should be set to role=presentational instead and then give the option to set it to img where needed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ARIA: img role - Accessibility - MDN Web Docs
The ARIA img role can be used to identify multiple elements inside page content that should be considered as a single image.
Read more >
SVG element with explicit role has non-empty accessible ...
This rule checks that each SVG image element that is explicitly included in the accessibility tree has a non-empty accessible name.
Read more >
5 Gotchas You're Gonna Face Getting Inline SVG Into ...
Since pointer-events are inherited, this will cause any of the SVG ā€œsub-elementsā€ to also not respond to pointer-events . Once you've set thisĀ ......
Read more >
Do I use <img>, <object>, or <embed> for SVG files?
After the image is loaded the onload="SVGInject(this) will trigger the injection and the <img> element will be replaced by the contents of the...
Read more >
Using SVG and Vue.js: A complete guide - LogRocket Blog
If that happens, it's fairly straightforward to add another <path> to the SVG file and another color to the colors object. Another benefit...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found