File tree 2 files changed +39
-2
lines changed
2 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -210,7 +210,7 @@ export default function DrawerPopup(props: DrawerPopupProps) {
210
210
...motionMaskStyle ,
211
211
...maskStyle ,
212
212
} }
213
- onClick = { maskClosable ? onClose : undefined }
213
+ onClick = { maskClosable && open ? onClose : undefined }
214
214
ref = { maskRef }
215
215
/>
216
216
) ;
Original file line number Diff line number Diff line change 1
- import { render } from '@testing-library/react' ;
1
+ import { render , fireEvent } from '@testing-library/react' ;
2
2
import React from 'react' ;
3
3
import Drawer from '../src' ;
4
4
@@ -36,4 +36,41 @@ describe('motion', () => {
36
36
background : 'red' ,
37
37
} ) ;
38
38
} ) ;
39
+
40
+ it ( 'mask close should only trigger once' , ( ) => {
41
+ let closeCount = 0 ;
42
+
43
+ const Demo = ( ) => {
44
+ const [ open , setOpen ] = React . useState ( true ) ;
45
+ const onClose = ( ) => {
46
+ closeCount += 1 ;
47
+ setOpen ( false ) ;
48
+ } ;
49
+
50
+ const sharedMotion = {
51
+ motionName : 'bamboo' ,
52
+ motionAppear : false ,
53
+ motionEnter : false ,
54
+ motionLeave : true ,
55
+ } ;
56
+
57
+ return (
58
+ < Drawer
59
+ motion = { sharedMotion }
60
+ maskMotion = { sharedMotion }
61
+ open = { open }
62
+ onClose = { onClose }
63
+ getContainer = { false }
64
+ />
65
+ ) ;
66
+ } ;
67
+
68
+ const { container } = render ( < Demo /> ) ;
69
+
70
+ for ( let i = 0 ; i < 10 ; i += 1 ) {
71
+ fireEvent . click ( container . querySelector ( '.rc-drawer-mask' ) ) ;
72
+ }
73
+
74
+ expect ( closeCount ) . toBe ( 1 ) ;
75
+ } ) ;
39
76
} ) ;
You can’t perform that action at this time.
0 commit comments