Skip to content

Commit 864fc91

Browse files
authored
Fix accidental camelCasing of CSS Variables (#153)
* Fix accidental camelCasing of CSS Variables * Add test * Re-add non-dimensional guard (whoops!)
1 parent a873856 commit 864fc91

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function styleObjToCss(s) {
2121
if (val!=null) {
2222
if (str) str += ' ';
2323
// str += jsToCss(prop);
24-
str += JS_TO_CSS[prop] || (JS_TO_CSS[prop] = prop.replace(/([A-Z])/g,'-$1').toLowerCase());
24+
str += prop[0]=='-' ? prop : (JS_TO_CSS[prop] || (JS_TO_CSS[prop] = prop.replace(/([A-Z])/g,'-$1').toLowerCase()));
2525
str += ': ';
2626
str += val;
2727
if (typeof val==='number' && IS_NON_DIMENSIONAL.test(prop)===false) {

test/render.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,13 @@ describe('render', () => {
145145
expect(rendered).to.equal(expected);
146146
});
147147

148+
it('should preserve CSS Custom Properties', () => {
149+
let rendered = render(<div style={{ '--foo': 1, '--foo-bar': '2' }} />),
150+
expected = `<div style="--foo: 1; --foo-bar: 2;"></div>`;
151+
152+
expect(rendered).to.equal(expected);
153+
});
154+
148155
it('should ignore empty object styles', () => {
149156
let rendered = render(<div style={{}} />),
150157
expected = `<div></div>`;

0 commit comments

Comments
 (0)