From 9d1ee9d089def5350d8e3332c282ff1207bdb470 Mon Sep 17 00:00:00 2001 From: martincupela Date: Mon, 9 Sep 2024 16:05:09 +0200 Subject: [PATCH] refactor: unmound popper element if closed in useDialogAnchor --- src/components/Dialog/DialogAnchor.tsx | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/components/Dialog/DialogAnchor.tsx b/src/components/Dialog/DialogAnchor.tsx index db27d8ee6..5e411ba0f 100644 --- a/src/components/Dialog/DialogAnchor.tsx +++ b/src/components/Dialog/DialogAnchor.tsx @@ -42,6 +42,10 @@ export function useDialogAnchor({ } }, [open, popperElement, update]); + if (popperElement && !open) { + setPopperElement(null); + } + return { attributes, setPopperElement, @@ -87,13 +91,6 @@ export const DialogAnchor = ({ }; }, [dialog, open]); - useEffect(() => { - if (!open) { - // setting element reference back to null allows to re-run the usePopper component once the component is re-rendered - setPopperElement(null); - } - }, [open, setPopperElement]); - // prevent rendering the dialog contents if the dialog should not be open / shown if (!open) { return null;