@@ -16,20 +16,28 @@ export default function useWinClick(
1616 const openRef = React . useRef ( open ) ;
1717 openRef . current = open ;
1818
19+ const popupPointerDownRef = React . useRef ( false ) ;
20+
1921 // Click to hide is special action since click popup element should not hide
2022 React . useEffect ( ( ) => {
2123 if ( clickToHide && popupEle && ( ! mask || maskClosable ) ) {
24+ const onPointerDown = ( ) => {
25+ popupPointerDownRef . current = false ;
26+ } ;
27+
2228 const onTriggerClose = ( e : MouseEvent ) => {
2329 if (
2430 openRef . current &&
25- ! inPopupOrChild ( e . composedPath ?.( ) ?. [ 0 ] || e . target )
31+ ! inPopupOrChild ( e . composedPath ?.( ) ?. [ 0 ] || e . target ) &&
32+ ! popupPointerDownRef . current
2633 ) {
2734 triggerOpen ( false ) ;
2835 }
2936 } ;
3037
3138 const win = getWin ( popupEle ) ;
3239
40+ win . addEventListener ( 'pointerdown' , onPointerDown , true ) ;
3341 win . addEventListener ( 'mousedown' , onTriggerClose , true ) ;
3442 win . addEventListener ( 'contextmenu' , onTriggerClose , true ) ;
3543
@@ -52,6 +60,7 @@ export default function useWinClick(
5260 }
5361
5462 return ( ) => {
63+ win . removeEventListener ( 'pointerdown' , onPointerDown , true ) ;
5564 win . removeEventListener ( 'mousedown' , onTriggerClose , true ) ;
5665 win . removeEventListener ( 'contextmenu' , onTriggerClose , true ) ;
5766
@@ -70,4 +79,10 @@ export default function useWinClick(
7079 } ;
7180 }
7281 } , [ clickToHide , targetEle , popupEle , mask , maskClosable ] ) ;
82+
83+ function onPopupPointerDown ( ) {
84+ popupPointerDownRef . current = true ;
85+ }
86+
87+ return onPopupPointerDown ;
7388}
0 commit comments