Skip to content
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

Attribute support: aria-labelledby #43

Open
chipcullen opened this issue Oct 20, 2016 · 5 comments
Open

Attribute support: aria-labelledby #43

chipcullen opened this issue Oct 20, 2016 · 5 comments
Assignees
Labels
Milestone

Comments

@chipcullen
Copy link

Per the summary:

Handles namespaced attributes (xlink), and other non-react attributes/tags, on component mounting, so the returned jsx will compile cleanly with babel.

One issue that we are running into, however, is using the aria-labelledby attribute. When authoring SVGs, this attribute can be used on the root <svg> element to aid screenreaders correctly announce what the SVG is supposed to be. Example usage:

<svg viewBox="0 0 126 126" xmlns="http://www.w3.org/2000/svg" aria-labelledby="close__title">
  <title id="close__title">
    Close
  </title>
  <path d="..." />
</svg>

(More background on this can be found on Tip #3 here)

React handles the aria-labelledby attribute just fine when the SVG is pasted directly into JSX - but, when loaded via svg-react-loader you get this console error:

Unknown props `ariaLabelledby` on <svg> tag. Remove these props from the element.

Would it be possible to amend SVG react loader to handle aria-labelledby, in addition to the other attributes it handles?

@jhamlet
Copy link
Owner

jhamlet commented Oct 20, 2016

@chipcullen Try using the next version of svg-react-loader npm install svg-react-loader@next and let me know if that solves your issue. (make sure you read the README since some things have changed -- no need for babel for instance)

I've done away with handling special attributes, and that version has a better API for special casing these kind of things (if that becomes necessary).

Thanks,

;-j

@jhamlet jhamlet added the bug label Oct 20, 2016
@jhamlet jhamlet added this to the v0.4.0 milestone Oct 20, 2016
@jhamlet jhamlet self-assigned this Oct 20, 2016
@chipcullen
Copy link
Author

@jhamlet I just tried, and unfortunately, no dice :(

I ran npm install svg-react-loader@next, which, finished with this in the console:

└── svg-react-loader@0.4.0-beta.2  invalid

And when I run npm info svg-react-loader version I get

0.3.7

Even though the directory in /node_modules/ is clearly the 0.4.0 version (the package.json indicates this)

Anyway, I can run webpack just fine, but I still get this console error in the browser:

Warning: Unknown prop `ariaLabelledby` on <svg> tag. Remove this prop from the element. For details, see https://fb.me/react-unknown-prop
    in svg (created by ... )

When inspecting the SVG in my browser dev tools, the aria-labelledby attribute doesn't even appear, though, that may be due to React suppressing the attribute.

If it helps, here is the React file with JSX:

image

And here is what I'm seeing in the browser vs what is in the SVG file:

image

And here is the browser console:

image

@jhamlet
Copy link
Owner

jhamlet commented Oct 21, 2016

@chipcullen thanks for the details.

I don't know what npm's issue is, but it looks like you're getting the correct version.

As a quick test (sorry, my bandwidth is limited at this time) can you try outputting an svg element through React (not using svg-react-loader, just plain react) with a property ariaLabelledby and then with ariaLabelledBy to see which one works?

The processor recognizes hyphens as places to camelCase things, however there is a way to special-case certain attribute names (look at the propsMap query parameter).

@cliener
Copy link

cliener commented Dec 7, 2016

I've recreated everything as per @chipcullen above and carried on with ^^.

I dropped an SVG inline into a JSX file and got the following:

  • ariaLabelledby: nothing
  • ariaLabelledBy: nothing
  • aria-labelledby: aria-labelledby

All of above rendered through svg-react-loader return nothing.

@anderskristiansen
Copy link

anderskristiansen commented Dec 8, 2016

I am having the same issue as @chipcullen.
I am getting Warning: Unknown prop 'ariaLabel' on <svg> tag. and Warning: Unknown prop 'dataSrc' on <img> tag..
I am using version 0.4.0-beta.2´. (Although npm states 0.3.7´)

Dropping in the SVG directly the attributes are printed. I've tried to use the ´propsMap´ query parameter, but It didn't do any difference. (I don't know if I used it correctly)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants