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

Use setProperty when setting style properties #9302

Merged
merged 5 commits into from Apr 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions scripts/fiber/tests-passing.txt
Expand Up @@ -816,6 +816,7 @@ src/renderers/dom/shared/__tests__/CSSPropertyOperations-test.js
* warns when miscapitalizing vendored style names
* should warn about style having a trailing semicolon
* should warn about style containing a NaN value
* should not warn when setting CSS variables

src/renderers/dom/shared/__tests__/DOMPropertyOperations-test.js
* should create markup for simple properties
Expand Down
8 changes: 7 additions & 1 deletion src/renderers/dom/shared/CSSPropertyOperations.js
Expand Up @@ -134,6 +134,10 @@ if (__DEV__) {
* @param {ReactDOMComponent} component
*/
var warnValidStyle = function(name, value, component) {
// Don't warn for CSS variables
if (name.indexOf('--') === 0) {
return;
}
var owner;
if (component) {
owner = component._currentElement._owner;
Expand Down Expand Up @@ -213,7 +217,9 @@ var CSSPropertyOperations = {
if (styleName === 'float') {
styleName = 'cssFloat';
}
if (styleValue) {
if (styleName.indexOf('--') === 0) {
style.setProperty(styleName, styleValue);
} else if (styleValue) {
style[styleName] = styleValue;
} else {
var expansion = hasShorthandPropertyBug &&
Expand Down
14 changes: 14 additions & 0 deletions src/renderers/dom/shared/__tests__/CSSPropertyOperations-test.js
Expand Up @@ -253,4 +253,18 @@ describe('CSSPropertyOperations', () => {
'\n\nCheck the render method of `Comp`.',
);
});

it('should not warn when setting CSS variables', () => {
class Comp extends React.Component {
render() {
return <div style={{'--foo-primary': 'red', backgroundColor: 'red'}} />;
}
}

spyOn(console, 'error');
var root = document.createElement('div');
ReactDOM.render(<Comp />, root);

expectDev(console.error.calls.count()).toBe(0);
});
});