Skip to content

Commit

Permalink
fix: rect-popup event bind error (#1922)
Browse files Browse the repository at this point in the history
  • Loading branch information
weird94 committed Apr 16, 2024
1 parent 4e970d4 commit ac17c69
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/design/src/components/popup/RectPopup.tsx
Expand Up @@ -112,9 +112,11 @@ function RectPopup(props: IRectPopupProps) {
]);

useEffect(() => {
const parent = nodeRef.current?.parentElement;
const current = nodeRef.current;
const parent = current?.parentElement;

if (parent) {
const handleClick = (e: MouseEvent) => {
const handleClickOther = (e: MouseEvent) => {
if (excludeOutside && (excludeOutside.indexOf(e.target as any) > -1)) {
return;
}
Expand All @@ -127,10 +129,11 @@ function RectPopup(props: IRectPopupProps) {
}
clickOtherFn(e);
};
parent.addEventListener('click', handleClick);

window.addEventListener('click', handleClickOther);

return () => {
parent.removeEventListener('click', handleClick);
window.removeEventListener('click', handleClickOther);
};
}
}, [anchorRect, anchorRect.bottom, anchorRect.left, anchorRect.right, anchorRect.top, clickOtherFn, excludeOutside]);
Expand Down

0 comments on commit ac17c69

Please sign in to comment.