Correctly trim strings for css properties

* If a unitless value is passed with a space it'll return `1 px`
This commit is contained in:
Ryan Seddon
2014-06-23 09:43:50 +10:00
parent 41ed67d222
commit 2bff5c5c7e
2 changed files with 11 additions and 0 deletions
@@ -68,6 +68,14 @@ describe('CSSPropertyOperations', function() {
})).toBe('left:0;margin:16px;opacity:0.5;padding:4px;');
});
it('should trim values so `px` will be appended correctly', function() {
expect(CSSPropertyOperations.createMarkupForStyles({
margin: '16 ',
opacity: 0.5,
padding: ' 4 '
})).toBe('margin:16px;opacity:0.5;padding:4px;');
});
it('should not append `px` to styles that might need a number', function() {
var CSSProperty = require('CSSProperty');
var unitlessProperties = Object.keys(CSSProperty.isUnitlessNumber);
@@ -54,6 +54,9 @@ function dangerousStyleValue(name, value) {
return '' + value; // cast to string
}
if (typeof value === 'string') {
value = value.trim();
}
return value + 'px';
}