Skip to content

Commit 9d1ee9d

Browse files
committed
refactor: unmound popper element if closed in useDialogAnchor
1 parent 9f071e4 commit 9d1ee9d

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/components/Dialog/DialogAnchor.tsx

+4-7
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ export function useDialogAnchor<T extends HTMLElement>({
4242
}
4343
}, [open, popperElement, update]);
4444

45+
if (popperElement && !open) {
46+
setPopperElement(null);
47+
}
48+
4549
return {
4650
attributes,
4751
setPopperElement,
@@ -87,13 +91,6 @@ export const DialogAnchor = ({
8791
};
8892
}, [dialog, open]);
8993

90-
useEffect(() => {
91-
if (!open) {
92-
// setting element reference back to null allows to re-run the usePopper component once the component is re-rendered
93-
setPopperElement(null);
94-
}
95-
}, [open, setPopperElement]);
96-
9794
// prevent rendering the dialog contents if the dialog should not be open / shown
9895
if (!open) {
9996
return null;

0 commit comments

Comments
 (0)