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.

SVG attributes and ARIA attributes with different pattern

See original GitHub issue

I have the following JSX sample, which is a SVG element:

    <svg className={className} viewBox="0 0 48 48" version="1.1"
      onClick={this.props.onClick} aria-label="Some random label">
      <g fill="none">
        <line strokeWidth="2" x1="24" y1="14" x2="24" y2="34"/>
        <line strokeWidth="2" x1="14" y1="24" x2="34" y2="24"/>
      </g>
    </svg>

In raw HTML strokeWidth is represented as stroke-width. It seems to me that all JSX attributes follow the camel-case format. So, I immediately thought on adding ariaLabel instead of aria-label.

Question: Is there a pattern for JSX attributes? If yes, why aria-* does not follow this pattern?

In fact, I like the idea of having stroke-* so that I don’t have to preprocess my raw svg to reactjs.

I understand that this could be the expected behavior, but I’m just trying to understand why the patterns are different for aria and svg.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
dwightjackcommented, Mar 16, 2017

Hi, related to this issue I’m trying to use a SVG with aria-* attributes as a component and React is complaining about unknown props on <svg> tag:

<svg xmlns="http://www.w3.org/2000/svg" role="img" viewBox="0 0 602.1 48.9" aria-labelledby="logo-expanded-title">
    <title id="logo-expanded-title">My title</title>
    <path role="presentation" d="..."/>
</svg>

Looking at the docs it seems both role and aria-* attributes are not allowed on SVG, but to enhance accessibility they’d be a good practice.

Right now my workaround is to use dangerouslySetInnerHTML but that’s not ideal.

0reactions
dwightjackcommented, Mar 16, 2017

Hi,

My bad! I investigated further the issue and I’ve found this issue. Looks like is something related to the loader I’m using.

Sorry!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using ARIA to enhance SVG accessibility - TPGi
It is possible to enhance the information exposed through the browser accessibility APIs with a handful of ARIA attributes.
Read more >
Accessible SVGs: Perfect Patterns For Screen Reader Users
This article outlines twelve distinct SVG patterns found “in the wild” and each alternative description announced when accessed by different ...
Read more >
SVG Accessibility/ARIA roles for charts - W3C Wiki
A graphical object that represents specific data values. Elements with a role that inherits from graphics-data can be annotated with various data-related  ......
Read more >
Accessible SVGs | CSS-Tricks
Scalable Vector Graphic (SVG) is emerging as the preferred graphic format to use on ... All <img> tags need the alt attribute to...
Read more >
SVG Elements and Attributes - O'Reilly Design System
A unique identifier for distinguishing this element from all other elements in the document. Used in SVG element cross-references, link targets, the JavaScript ......
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