-
Notifications
You must be signed in to change notification settings - Fork 47.6k
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
Better SVG Support for namespaced attributes #2250
Comments
The exception that is raised, when we try to put some namespaced attributes: |
I already faced the same issue for image element. I opened an issue and <svg dangerouslySetInnerHTML={ {__html: "<image id=" + this.props.id + " x=" + this.props.x + " y=" + " width='"+ (this.props.width-20) +"' height='"+ "' fill='#90' stroke='#000' style='cursor:pointer' xlink:href='" + "'/>" } }/> 2014-09-28 15:20 GMT+01:00 Bruno Ledesma notifications@github.com:
Paulo Jorge Dias |
+1 on this. React could be a really great platform for doing SVG, but it's hard to use SVG to full effect without xlink:href and friends. |
Hi @edmspjp I had the same issue, but it seems add dangerouslySetInnerHTML to tag still has the same problem. And take the whole svg tag as dangerouslySetInnerHTML attr to its parent tag works for me. I am not sure if you met the problem before. var svgTag='<svg><image..></svg>';
<div dangerouslySetInnerHTML={__html: svgTag} /> |
Any updates on or further plans for supporting SVG namespaced elements and attributes? |
Seems it's still necessary to implement SVGs using |
I can recommend to use a combination of d3 and react. When ever I need to use namespaced attributes I use d3 in the |
+1 for this request. I need React to render an inline SVG that has an image inside a clipping path, and it's getting hung on the |
@dujuanxian's workaround helped me get through this, provided double (not single) braces are used, of course:
|
Just to show an example using d3 for the non-react-svg-stuff: https://github.com/FH-Potsdam/shifted-maps/blob/master/app/client/components/place-map.js#L21-L40 I used d3 here, because React is not able to set |
+1 Any updates on this? Thx for the workaround. Hope it'll work until this is fixed. |
See in How SVG Fragment Identifiers Work 2015-07-29 23:12 GMT+01:00 Lennart Hildebrandt notifications@github.com:
Paulo Jorge Dias |
In the |
Do you also get the proper namespace attribute for the namespace itself? |
Not quite sure I understand what you mean. Can you give me an explanation/example? |
To be able to get links working, you also need an attribute for the namespace itself. <svg width="800" height="600">
<a xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.github.com/"><!-- ... --></a>
</svg> Does React handle this in your example? |
No, it does only pass |
@lennerd My understanding is that the xmlns:xlink is not required in HTML. |
After looking through the SVG config and some tests it seems like the namespace is passed to the DOM node through the |
Sounds promising. Would be great to remove the d3 dependency. |
Yes, as |
Image embed doesn't work with React 0.13 facebook/react#2250 This branch upgrades to 0.14-rc1, which breaks Reagent reagent-project/reagent#184
xmlns:xlink is not required in HTML only if all the SVG is inline, but it is necessary for some tricky case: In my case, I need to have an image inside defs, to be used then by and to do that xmlns:xlink is apparently necessary. |
Just confirming that |
I'm still getting this error, even when using react 0.14.x or the newer react 15.0.2. I'm not sure if I'm just missing something else that needs to be updated. I'm writing a library so I'm only using react, not react-dom...I'm not sure if it's babel or something else. Here's the code:
And here's my package.json file:
and finally the error (which is the same as others were getting):
|
@QuietOmen you want |
@zpao thanks, for some reason I missed that commented above, so thanks for repeating it. |
Apologies if I missed this somewhere, but what about styling SVG inline? <style type="text/css" >
<![CDATA[
circle {
stroke: #006600;
fill: #cc0000;
}
]]>
</style> |
<style type="text/css" dangerouslySetInnerHTML={{__html: `
<![CDATA[
circle {
stroke: #006600;
fill: #cc0000;
}
]]>
`}}/> |
@zpao But then it's only static, though, right? Like, you can't eval props in there? e.g.
|
What you pass is just a string. You can generate the string dynamically—either with template literals or good ol’ concatenation. <style type="text/css" dangerouslySetInnerHTML={{__html: `
<![CDATA[
circle {
stroke: ${props.color};
fill: #cc0000;
}
]]>
`}}/> should work fine. |
Here's a JSFiddle with a working example: https://jsfiddle.net/yp0q6okn/ |
A mi me funciono reemplazando xmlns:xlink por xlinkHref y elimine un atributo mas xml:space="preserve" con eso me ando perfecto la referencia lo tome de un pagina |
it's work for me |
We are trying to use React for a SVG document. But we are facing problems for namespaced attributes.
For instance, this element cant be constructed with React:
We cant build a JSX for a xmlns:xlink attribute. Is there any way to solve this?
The text was updated successfully, but these errors were encountered: