Skip to content

Commit 39876c4

Browse files
authored
fix: onClose only trigger when open (#371)
1 parent 8b8bb36 commit 39876c4

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

src/DrawerPopup.tsx

+1-1
Original file line numberDiff line numberDiff 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
);

tests/motion.spec.tsx

+38-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { render } from '@testing-library/react';
1+
import { render, fireEvent } from '@testing-library/react';
22
import React from 'react';
33
import 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
});

0 commit comments

Comments
 (0)