Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,18 @@ describe('ReactDOMComponent', function() {
expect(console.error.calls.length).toBe(2);
});

it('should not warn for "0" as a unitless style value', function() {
spyOn(console, 'error');
var Component = React.createClass({
render: function() {
return <div style={{margin: '0'}} />;
},
});

ReactTestUtils.renderIntoDocument(<Component />);
expect(console.error.calls.length).toBe(0);
});

it('should warn nicely about NaN in style', function() {
spyOn(console, 'error');

Expand Down
6 changes: 4 additions & 2 deletions src/renderers/dom/shared/dangerousStyleValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ function dangerousStyleValue(name, value, component) {
}

var isNonNumeric = isNaN(value);
if (isNonNumeric || value === 0 || value === '0' ||
if (isNonNumeric || value === 0 ||
isUnitlessNumber.hasOwnProperty(name) && isUnitlessNumber[name]) {
return '' + value; // cast to string
}

if (typeof value === 'string') {
if (__DEV__) {
if (component) {
// Allow '0' to pass through without warning. 0 is already special and
// doesn't require units, so we don't need to warn about it.
if (component && value !== '0') {
var owner = component._currentElement._owner;
var ownerName = owner ? owner.getName() : null;
if (ownerName && !styleWarnings[ownerName]) {
Expand Down