Skip to content

Commit

Permalink
refactor: unmound popper element if closed in useDialogAnchor
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinCupela committed Sep 9, 2024
1 parent 9f071e4 commit 9d1ee9d
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/components/Dialog/DialogAnchor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export function useDialogAnchor<T extends HTMLElement>({
}
}, [open, popperElement, update]);

if (popperElement && !open) {
setPopperElement(null);
}

return {
attributes,
setPopperElement,
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 9d1ee9d

Please sign in to comment.