File tree Expand file tree Collapse file tree 2 files changed +39
-2
lines changed
Expand file tree Collapse file tree 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) {
210210 ...motionMaskStyle ,
211211 ...maskStyle ,
212212 } }
213- onClick = { maskClosable ? onClose : undefined }
213+ onClick = { maskClosable && open ? onClose : undefined }
214214 ref = { maskRef }
215215 />
216216 ) ;
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' ;
22import React from 'react' ;
33import Drawer from '../src' ;
44
@@ -36,4 +36,41 @@ describe('motion', () => {
3636 background : 'red' ,
3737 } ) ;
3838 } ) ;
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+ } ) ;
3976} ) ;
You can’t perform that action at this time.
0 commit comments