Skip to content

Commit

Permalink
fix: clear popper listener register on unmount
Browse files Browse the repository at this point in the history
refs: (#95)
  • Loading branch information
beawar authored Jul 25, 2022
1 parent fe07401 commit 7c8facd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/components/display/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ const Popover = React.forwardRef<HTMLDivElement, PopoverProps>(function PopoverF
}
}, [onMouseMove, anchorEl]);

const innerOnClose = useCallback(() => !activateOnHover && onClose(), [activateOnHover, onClose]);
const innerOnClose = useCallback(() => {
!activateOnHover && onClose();
}, [activateOnHover, onClose]);

const onMouseEnter = useCallback(
() =>
Expand Down
6 changes: 4 additions & 2 deletions src/components/display/Popper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,17 @@ const Popper = React.forwardRef<HTMLDivElement, PopperProps>(function PopperFn(
}, [open, placement, anchorEl, virtualElement, popperRef]);

useEffect(() => {
let listenerTimeout: ReturnType<typeof setTimeout>;
if (open) {
setTimeout(() => {
listenerTimeout = setTimeout(() => {
windowObj.document.addEventListener('click', closePopper);
}, 1);
}
return (): void => {
windowObj.document.removeEventListener('click', closePopper);
listenerTimeout && clearTimeout(listenerTimeout);
};
}, [open, closePopper, windowObj.document]);
}, [open, closePopper, windowObj]);

useEffect(() => {
const startSentinelRefSave = startSentinelRef.current;
Expand Down

0 comments on commit 7c8facd

Please sign in to comment.