diff --git a/packages/react-components/src/components/Popover/Popover.tsx b/packages/react-components/src/components/Popover/Popover.tsx index 792ca3299..239da0b7c 100644 --- a/packages/react-components/src/components/Popover/Popover.tsx +++ b/packages/react-components/src/components/Popover/Popover.tsx @@ -17,11 +17,13 @@ export interface IPopoverProps { isVisible?: boolean; flipOptions?: Parameters[0]; triggerRenderer: () => React.ReactNode; + onClose?: () => void; } export const Popover: React.FC = (props) => { const { triggerRenderer, + onClose, children, className, placement, @@ -29,6 +31,7 @@ export const Popover: React.FC = (props) => { isVisible = false, } = props; const [visible, setVisibility] = React.useState(false); + const prevVisibleState = React.useRef(false); const { x, @@ -48,6 +51,13 @@ export const Popover: React.FC = (props) => { setVisibility(isVisible); }, [isVisible]); + React.useEffect(() => { + if (onClose && prevVisibleState.current !== visible && !visible) { + onClose(); + } + prevVisibleState.current = visible; + }, [visible]); + React.useEffect(() => { if (!refs.reference.current || !refs.floating.current) { return;