Skip to content

Commit

Permalink
Merge 0d970b2 into 6ff8d85
Browse files Browse the repository at this point in the history
  • Loading branch information
gados3 committed May 28, 2019
2 parents 6ff8d85 + 0d970b2 commit 4e2e7f4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ scripts/__pycache__/
examples/**/*-bundle.js
node_modules/
.idea/
.vscode
_book
*.patch
*.diff
Expand Down
17 changes: 16 additions & 1 deletion specs/Modal.events.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
escKeyDown,
tabKeyDown,
renderModal,
emptyDOM
emptyDOM,
unmountModal
} from "./helper";

export default () => {
Expand All @@ -36,6 +37,20 @@ export default () => {
onAfterCloseCallback.called.should.be.ok();
});

it("should not trigger onAfterClose callback when unmounting a closed modal", () => {
const onAfterCloseCallback = sinon.spy();
renderModal({ isOpen: false, onAfterClose: onAfterCloseCallback });
unmountModal();
onAfterCloseCallback.called.should.not.be.ok();
});

it("should trigger onAfterClose callback when unmounting an opened modal", () => {
const onAfterCloseCallback = sinon.spy();
renderModal({ isOpen: true, onAfterClose: onAfterCloseCallback });
unmountModal();
onAfterCloseCallback.called.should.be.ok();
});

it("keeps focus inside the modal when child has no tabbable elements", () => {
let tabPrevented = false;
const modal = renderModal({ isOpen: true }, "hello");
Expand Down
4 changes: 3 additions & 1 deletion src/components/ModalPortal.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ export default class ModalPortal extends Component {
}

componentWillUnmount() {
this.afterClose();
if (this.state.isOpen) {
this.afterClose();
}
clearTimeout(this.closeTimer);
}

Expand Down

0 comments on commit 4e2e7f4

Please sign in to comment.