Skip to content

Commit 96ef53a

Browse files
committed
Merge pull request react-bootstrap#1079 from zerkms/modal-unmount
Modal: added finalisation for the component when it was unbound from the tree
2 parents 9b8089d + a4ce7e1 commit 96ef53a

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

src/Modal.js

Lines changed: 6 additions & 0 deletions
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

Lines changed: 16 additions & 0 deletions
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)