diff --git a/src/hooks/useWinClick.ts b/src/hooks/useWinClick.ts index f33f05b0..abcc80e5 100644 --- a/src/hooks/useWinClick.ts +++ b/src/hooks/useWinClick.ts @@ -10,7 +10,7 @@ export default function useWinClick( popupEle: HTMLElement, mask: boolean, maskClosable: boolean, - inPopupOrChild: (target: EventTarget) => boolean, + inPopupOrChild: (target: EventTarget,composedPathTargetList:EventTarget[]) => boolean, triggerOpen: (open: boolean) => void, ) { const openRef = React.useRef(open); @@ -19,8 +19,8 @@ export default function useWinClick( // Click to hide is special action since click popup element should not hide React.useEffect(() => { if (clickToHide && popupEle && (!mask || maskClosable)) { - const onTriggerClose = ({ target }: MouseEvent) => { - if (openRef.current && !inPopupOrChild(target)) { + const onTriggerClose = (e: MouseEvent) => { + if (openRef.current && !inPopupOrChild(e.target,e.composedPath())) { triggerOpen(false); } }; diff --git a/src/index.tsx b/src/index.tsx index 4a7b990f..fda973e2 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -272,7 +272,7 @@ export function generateTrigger( const originChildProps = child?.props || {}; const cloneProps: typeof originChildProps = {}; - const inPopupOrChild = useEvent((ele: any) => { + const inPopupOrChild = useEvent((ele: any,composedPathTargetList:EventTarget[]) => { const childDOM = targetEle; return ( @@ -284,7 +284,7 @@ export function generateTrigger( ele === popupEle || Object.values(subPopupElements.current).some( (subPopupEle) => subPopupEle?.contains(ele) || ele === subPopupEle, - ) + )||composedPathTargetList.some(tar=>targetEle===tar) ); });