Skip to content
This repository was archived by the owner on Dec 16, 2021. It is now read-only.

Commit e0bc12c

Browse files
committed
Add support for deprecated camelCase'd SVG props. Fixes #222.
1 parent 7402873 commit e0bc12c

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

‎src/index.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ const AUTOBIND_BLACKLIST = {
2222
};
2323

2424

25+
const CAMEL_PROPS = /^(accent|alignment|arabic|baseline|cap|clip|color|fill|flood|font|glyph|horiz|marker|overline|paint|stop|strikethrough|stroke|text|underline|unicode|units|v|vert|word|writing|x)[A-Z]/g;
26+
27+
2528
const BYPASS_HOOK = {};
2629

2730
/*global process*/
@@ -96,6 +99,15 @@ function handleVNode(vnode) {
9699

97100
if (vnode.children) a.children = vnode.children;
98101
}
102+
else if (a) {
103+
for (let i in a) {
104+
if (a.hasOwnProperty(i) && i.match(CAMEL_PROPS)) {
105+
a[i.replace(/([A-Z0-9])/g, '-$1').toLowerCase()] = a[i];
106+
delete a[i];
107+
}
108+
}
109+
}
110+
}
99111

100112

101113

‎test/svg.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,14 @@ describe('svg', () => {
3939

4040
expect(scratch.innerHTML).to.equal('<svg viewBox="0 0 360 360"><path stroke="white" fill="black" d="M347.1 357.9L183.3 256.5 13 357.9V1.7h334.1v356.2zM58.5 47.2v231.4l124.8-74.1 118.3 72.8V47.2H58.5z"></path></svg>');
4141
});
42+
43+
it('should render SVG to DOM', () => {
44+
React.render((
45+
<svg viewBox="0 0 100 100">
46+
<text textAnchor="mid">foo</text>
47+
</svg>
48+
), scratch);
49+
50+
expect(scratch.innerHTML).to.equal('<svg viewBox="0 0 100 100"><text text-anchor="mid">foo</text></svg>');
51+
});
4252
});

0 commit comments

Comments
 (0)