Skip to content

Commit

Permalink
Don't camelCase CSS custom properties
Browse files Browse the repository at this point in the history
  • Loading branch information
tylersticka committed Mar 13, 2023
1 parent 945ed72 commit 3e6aae7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ function createStyleJsonFromString(styleString) {
}

if (key != null && value != null && key.length > 0 && value.length > 0) {
jsonStyles[camelCase(key)] = value;
key = key.trim();

// Don't camelCase CSS custom properties
if (key.indexOf('--') !== 0) {
key = camelCase(key);
}

jsonStyles[key] = value;
}
}
return jsonStyles;
Expand Down
9 changes: 9 additions & 0 deletions test/html-to-react-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ describe('Html2React', () => {
assert.equal(reactHtml, htmlExpected);
});

it('should return a valid HTML string with custom properties in inline styles', () => {
const htmlInput = '<div style="color:var(--color-example);--color-example:black"></div>';

const reactComponent = parser.parse(htmlInput);
const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent);

assert.equal(reactHtml, htmlInput);
});

it('should return a valid HTML string with data attributes', () => {
const htmlInput = '<div data-test-attribute="data attribute value"></div>';

Expand Down

0 comments on commit 3e6aae7

Please sign in to comment.