mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Unbreaking falsy check on style values
Style values can be the number zero which is an actual value. So we check for null instead. The empty string case falls through.
This commit is contained in:
committed by
Paul O’Shannessy
parent
b525a0c061
commit
770ec5946a
@@ -247,7 +247,8 @@ ReactNativeComponent.Mixin = {
|
||||
if (lastProp) {
|
||||
// Unset styles on `lastProp` but not on `nextProp`.
|
||||
for (styleName in lastProp) {
|
||||
if (lastProp.hasOwnProperty(styleName) && !nextProp[styleName]) {
|
||||
if (lastProp.hasOwnProperty(styleName) &&
|
||||
!nextProp.hasOwnProperty(styleName)) {
|
||||
styleUpdates = styleUpdates || {};
|
||||
styleUpdates[styleName] = '';
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ describe('ReactNativeComponent', function() {
|
||||
});
|
||||
|
||||
it("should update styles when mutating style object", function() {
|
||||
var styles = { display: 'none', fontFamily: 'Arial' };
|
||||
var styles = { display: 'none', fontFamily: 'Arial', opacity: 0 };
|
||||
var stub = ReactTestUtils.renderIntoDocument(<div style={styles} />);
|
||||
|
||||
var stubStyle = stub.getDOMNode().style;
|
||||
@@ -82,12 +82,21 @@ describe('ReactNativeComponent', function() {
|
||||
stub.receiveProps({ style: styles }, transaction);
|
||||
expect(stubStyle.display).toEqual('block');
|
||||
expect(stubStyle.fontFamily).toEqual('Arial');
|
||||
expect(stubStyle.opacity).toEqual('0');
|
||||
|
||||
styles.fontFamily = 'Helvetica';
|
||||
|
||||
stub.receiveProps({ style: styles }, transaction);
|
||||
expect(stubStyle.display).toEqual('block');
|
||||
expect(stubStyle.fontFamily).toEqual('Helvetica');
|
||||
expect(stubStyle.opacity).toEqual('0');
|
||||
|
||||
styles.opacity = 0.5;
|
||||
|
||||
stub.receiveProps({ style: styles }, transaction);
|
||||
expect(stubStyle.display).toEqual('block');
|
||||
expect(stubStyle.fontFamily).toEqual('Helvetica');
|
||||
expect(stubStyle.opacity).toEqual('0.5');
|
||||
});
|
||||
|
||||
it("should update styles if initially null", function() {
|
||||
|
||||
@@ -74,8 +74,10 @@ var CSSPropertyOperations = {
|
||||
if (!styles.hasOwnProperty(styleName)) {
|
||||
continue;
|
||||
}
|
||||
var styleValue = styles[styleName];
|
||||
if (!styleValue) {
|
||||
var styleValue = dangerousStyleValue(styleName, styles[styleName]);
|
||||
if (styleValue) {
|
||||
style[styleName] = styleValue;
|
||||
} else {
|
||||
var expansion = CSSProperty.shorthandPropertyExpansions[styleName];
|
||||
if (expansion) {
|
||||
// Shorthand property that IE8 won't like unsetting, so unset each
|
||||
@@ -86,8 +88,6 @@ var CSSPropertyOperations = {
|
||||
} else {
|
||||
style[styleName] = '';
|
||||
}
|
||||
} else {
|
||||
style[styleName] = dangerousStyleValue(styleName, styleValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user