File tree Expand file tree Collapse file tree 3 files changed +20
-2
lines changed Expand file tree Collapse file tree 3 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ scripts/__pycache__/
55examples /** /* -bundle.js
66node_modules /
77.idea /
8+ .vscode
89_book
910* .patch
1011* .diff
Original file line number Diff line number Diff line change @@ -12,7 +12,8 @@ import {
1212 escKeyDown ,
1313 tabKeyDown ,
1414 renderModal ,
15- emptyDOM
15+ emptyDOM ,
16+ unmountModal
1617} from "./helper" ;
1718
1819export default ( ) => {
@@ -36,6 +37,20 @@ export default () => {
3637 onAfterCloseCallback . called . should . be . ok ( ) ;
3738 } ) ;
3839
40+ it ( "should not trigger onAfterClose callback when unmounting a closed modal" , ( ) => {
41+ const onAfterCloseCallback = sinon . spy ( ) ;
42+ renderModal ( { isOpen : false , onAfterClose : onAfterCloseCallback } ) ;
43+ unmountModal ( ) ;
44+ onAfterCloseCallback . called . should . not . be . ok ( ) ;
45+ } ) ;
46+
47+ it ( "should trigger onAfterClose callback when unmounting an opened modal" , ( ) => {
48+ const onAfterCloseCallback = sinon . spy ( ) ;
49+ renderModal ( { isOpen : true , onAfterClose : onAfterCloseCallback } ) ;
50+ unmountModal ( ) ;
51+ onAfterCloseCallback . called . should . be . ok ( ) ;
52+ } ) ;
53+
3954 it ( "keeps focus inside the modal when child has no tabbable elements" , ( ) => {
4055 let tabPrevented = false ;
4156 const modal = renderModal ( { isOpen : true } , "hello" ) ;
Original file line number Diff line number Diff line change @@ -114,7 +114,9 @@ export default class ModalPortal extends Component {
114114 }
115115
116116 componentWillUnmount ( ) {
117- this . afterClose ( ) ;
117+ if ( this . state . isOpen ) {
118+ this . afterClose ( ) ;
119+ }
118120 clearTimeout ( this . closeTimer ) ;
119121 }
120122
You can’t perform that action at this time.
0 commit comments