Skip to content

Commit 3139e85

Browse files
Lucas Simeondiasbruno
Lucas Simeon
authored andcommitted
[added] refresh portalClassName on componentWillUpdate
1 parent 09f8ac0 commit 3139e85

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

lib/components/Modal.js

+6
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ var Modal = createReactClass({
7373
this.renderPortal(this.props);
7474
},
7575

76+
componentWillUpdate: function(newProps) {
77+
if(newProps.portalClassName !== this.props.portalClassName) {
78+
this.node.className = newProps.portalClassName;
79+
}
80+
},
81+
7682
componentWillReceiveProps: function(newProps) {
7783
if (newProps.isOpen) refCount.add(this);
7884
if (!newProps.isOpen) refCount.remove(this);

specs/Modal.spec.js

+38
Original file line numberDiff line numberDiff line change
@@ -341,4 +341,42 @@ describe('State', () => {
341341

342342
document.body.removeChild(currentDiv);
343343
});
344+
345+
it('verify that portalClassName is refreshed on component update', () => {
346+
var node = document.createElement('div');
347+
var modal = null;
348+
349+
var App = React.createClass({
350+
getInitialState: function () {
351+
return { testHasChanged: false };
352+
},
353+
354+
componentDidMount: function() {
355+
expect(modal.node.className).toEqual('myPortalClass');
356+
357+
this.setState({
358+
testHasChanged: true
359+
});
360+
},
361+
362+
componentDidUpdate: function() {
363+
expect(modal.node.className).toEqual('myPortalClass-modifier');
364+
},
365+
366+
render: function() {
367+
return (
368+
<div>
369+
<Modal
370+
ref={modalComponent => { modal = modalComponent; }}
371+
isOpen={true}
372+
portalClassName={this.state.testHasChanged === true ? 'myPortalClass-modifier' : 'myPortalClass'}>
373+
</Modal>
374+
</div>
375+
);
376+
}
377+
});
378+
379+
Modal.setAppElement(node);
380+
ReactDOM.render(<App />, node);
381+
});
344382
});

0 commit comments

Comments
 (0)