File tree 3 files changed +20
-2
lines changed
3 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ scripts/__pycache__/
5
5
examples /** /* -bundle.js
6
6
node_modules /
7
7
.idea /
8
+ .vscode
8
9
_book
9
10
* .patch
10
11
* .diff
Original file line number Diff line number Diff line change @@ -12,7 +12,8 @@ import {
12
12
escKeyDown ,
13
13
tabKeyDown ,
14
14
renderModal ,
15
- emptyDOM
15
+ emptyDOM ,
16
+ unmountModal
16
17
} from "./helper" ;
17
18
18
19
export default ( ) => {
@@ -36,6 +37,20 @@ export default () => {
36
37
onAfterCloseCallback . called . should . be . ok ( ) ;
37
38
} ) ;
38
39
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
+
39
54
it ( "keeps focus inside the modal when child has no tabbable elements" , ( ) => {
40
55
let tabPrevented = false ;
41
56
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 {
114
114
}
115
115
116
116
componentWillUnmount ( ) {
117
- this . afterClose ( ) ;
117
+ if ( this . state . isOpen ) {
118
+ this . afterClose ( ) ;
119
+ }
118
120
clearTimeout ( this . closeTimer ) ;
119
121
}
120
122
You can’t perform that action at this time.
0 commit comments