Skip to content

Commit

Permalink
[added] refresh portalClassName on componentWillUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Simeon authored and diasbruno committed Jun 15, 2017
1 parent 09f8ac0 commit 3139e85
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/components/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ var Modal = createReactClass({
this.renderPortal(this.props);
},

componentWillUpdate: function(newProps) {
if(newProps.portalClassName !== this.props.portalClassName) {
this.node.className = newProps.portalClassName;
}
},

componentWillReceiveProps: function(newProps) {
if (newProps.isOpen) refCount.add(this);
if (!newProps.isOpen) refCount.remove(this);
Expand Down
38 changes: 38 additions & 0 deletions specs/Modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,4 +341,42 @@ describe('State', () => {

document.body.removeChild(currentDiv);
});

it('verify that portalClassName is refreshed on component update', () => {
var node = document.createElement('div');
var modal = null;

var App = React.createClass({
getInitialState: function () {
return { testHasChanged: false };
},

componentDidMount: function() {
expect(modal.node.className).toEqual('myPortalClass');

this.setState({
testHasChanged: true
});
},

componentDidUpdate: function() {
expect(modal.node.className).toEqual('myPortalClass-modifier');
},

render: function() {
return (
<div>
<Modal
ref={modalComponent => { modal = modalComponent; }}
isOpen={true}
portalClassName={this.state.testHasChanged === true ? 'myPortalClass-modifier' : 'myPortalClass'}>
</Modal>
</div>
);
}
});

Modal.setAppElement(node);
ReactDOM.render(<App />, node);
});
});

0 comments on commit 3139e85

Please sign in to comment.