Skip to content

Commit

Permalink
chore: fix portal mock
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Feb 8, 2023
1 parent d0d0af6 commit 7ca1881
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/mock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,33 @@ import * as React from 'react';
import { generateTrigger } from './index';

interface MockPortalProps {
open?: boolean;
autoDestroy?: boolean;
children: React.ReactElement;
getContainer?: () => HTMLElement;
}

const MockPortal: React.FC<MockPortalProps> = ({
open,
autoDestroy,
children,
getContainer,
}) => {
const [visible, setVisible] = React.useState(open);

React.useEffect(() => {
getContainer?.();
});

return children;
React.useEffect(() => {
if (open) {
setVisible(true);
} else if (!open && autoDestroy) {
setVisible(false);
}
}, [open, autoDestroy]);

return visible ? children : null;
};

export default generateTrigger(MockPortal);

0 comments on commit 7ca1881

Please sign in to comment.