Skip to content

Commit

Permalink
Merge pull request facebook#3614 from kassens/set_style_null
Browse files Browse the repository at this point in the history
Fix for style not always reset when set to null
  • Loading branch information
zpao committed Apr 13, 2015
1 parent 631887d commit 0e70730
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/browser/ui/ReactDOMComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ ReactDOMComponent.Mixin = {
if (propKey === STYLE) {
if (nextProp) {
nextProp = this._previousStyleCopy = assign({}, nextProp);
} else {
this._previousStyleCopy = null;
}
if (lastProp) {
// Unset styles on `lastProp` but not on `nextProp`.
Expand Down
21 changes: 21 additions & 0 deletions src/browser/ui/__tests__/ReactDOMComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,27 @@ describe('ReactDOMComponent', function() {
expect(stubStyle.display).toEqual('block');
});

it("should update styles if updated to null multiple times", function() {
var styles = null;
var container = document.createElement('div');
React.render(<div style={styles} />, container);

styles = {display: 'block'};
var stubStyle = container.firstChild.style;

React.render(<div style={styles} />, container);
expect(stubStyle.display).toEqual('block');

React.render(<div style={null} />, container);
expect(stubStyle.display).toEqual('');

React.render(<div style={styles} />, container);
expect(stubStyle.display).toEqual('block');

React.render(<div style={null} />, container);
expect(stubStyle.display).toEqual('');
});

it("should remove attributes", function() {
var container = document.createElement('div');
React.render(<img height='17' />, container);
Expand Down

0 comments on commit 0e70730

Please sign in to comment.