mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Merge pull request #1642 from ryanseddon/trimCSSValues
Correctly trim strings for css properties
This commit is contained in:
@@ -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';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user