From 26803e9ec5a5e3f4552643b9b256c588ee1e3fb6 Mon Sep 17 00:00:00 2001 From: Marcin Sawicki Date: Mon, 20 Feb 2023 16:12:28 +0100 Subject: [PATCH 1/3] added onClose prop to pass handler for popover close action --- .../src/components/Popover/Popover.tsx | 10 ++++++++++ 1 file changed, 10 insertions(+) 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; From 14c14a632eb0b59ca941e936b64c18aba5ceb1fd Mon Sep 17 00:00:00 2001 From: Marcin Sawicki Date: Tue, 21 Feb 2023 08:48:20 +0100 Subject: [PATCH 2/3] test commit --- .../src/components/Popover/Popover.stories.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/react-components/src/components/Popover/Popover.stories.tsx b/packages/react-components/src/components/Popover/Popover.stories.tsx index 990ac6ff3..d2c684e69 100644 --- a/packages/react-components/src/components/Popover/Popover.stories.tsx +++ b/packages/react-components/src/components/Popover/Popover.stories.tsx @@ -45,7 +45,8 @@ const placementsWithUnselect = ['default', ...placements]; const OpenChat = () => { return (
- Open chat{' '} + {' '} + Open chat{' '}
); }; From f812a7d2b293e296633e8c5675e610027905f7b6 Mon Sep 17 00:00:00 2001 From: Marcin Sawicki Date: Tue, 21 Feb 2023 09:07:44 +0100 Subject: [PATCH 3/3] test commit --- .../src/components/Popover/Popover.stories.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/react-components/src/components/Popover/Popover.stories.tsx b/packages/react-components/src/components/Popover/Popover.stories.tsx index d2c684e69..990ac6ff3 100644 --- a/packages/react-components/src/components/Popover/Popover.stories.tsx +++ b/packages/react-components/src/components/Popover/Popover.stories.tsx @@ -45,8 +45,7 @@ const placementsWithUnselect = ['default', ...placements]; const OpenChat = () => { return (
- {' '} - Open chat{' '} + Open chat{' '}
); };