Skip to content

Commit 7ca1881

Browse files
committed
chore: fix portal mock
1 parent d0d0af6 commit 7ca1881

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/mock.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,33 @@ import * as React from 'react';
22
import { generateTrigger } from './index';
33

44
interface MockPortalProps {
5+
open?: boolean;
6+
autoDestroy?: boolean;
57
children: React.ReactElement;
68
getContainer?: () => HTMLElement;
79
}
810

911
const MockPortal: React.FC<MockPortalProps> = ({
12+
open,
13+
autoDestroy,
1014
children,
1115
getContainer,
1216
}) => {
17+
const [visible, setVisible] = React.useState(open);
18+
1319
React.useEffect(() => {
1420
getContainer?.();
1521
});
1622

17-
return children;
23+
React.useEffect(() => {
24+
if (open) {
25+
setVisible(true);
26+
} else if (!open && autoDestroy) {
27+
setVisible(false);
28+
}
29+
}, [open, autoDestroy]);
30+
31+
return visible ? children : null;
1832
};
1933

2034
export default generateTrigger(MockPortal);

0 commit comments

Comments
 (0)