Skip to content

Commit a4ce7e1

Browse files
committedJul 30, 2015
[fixed] added finalisation for the Modal when it was unbound from the tree
1 parent 23f3e0c commit a4ce7e1

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed
 

‎src/Modal.js

+6
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,12 @@ const Modal = React.createClass({
277277
}
278278
},
279279

280+
componentWillUnmount() {
281+
if (this.props.show) {
282+
this.onHide();
283+
}
284+
},
285+
280286
onShow() {
281287
const doc = domUtils.ownerDocument(this);
282288
const win = domUtils.ownerWindow(this);

‎test/ModalSpec.js

+16
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,22 @@ describe('Modal', function () {
197197
, mountPoint);
198198
});
199199

200+
it('Should unbind listeners when unmounted', function() {
201+
render(
202+
<div>
203+
<Modal show onHide={() => null} animation={false}>
204+
<strong>Foo bar</strong>
205+
</Modal>
206+
</div>
207+
, mountPoint);
208+
209+
assert.include(document.body.className, 'modal-open');
210+
211+
render(<div />, mountPoint);
212+
213+
assert.notInclude(document.body.className, 'modal-open');
214+
});
215+
200216
describe('Focused state', function () {
201217
let focusableContainer = null;
202218

0 commit comments

Comments
 (0)