@@ -16,20 +16,28 @@ export default function useWinClick(
16
16
const openRef = React . useRef ( open ) ;
17
17
openRef . current = open ;
18
18
19
+ const popupPointerDownRef = React . useRef ( false ) ;
20
+
19
21
// Click to hide is special action since click popup element should not hide
20
22
React . useEffect ( ( ) => {
21
23
if ( clickToHide && popupEle && ( ! mask || maskClosable ) ) {
24
+ const onPointerDown = ( ) => {
25
+ popupPointerDownRef . current = false ;
26
+ } ;
27
+
22
28
const onTriggerClose = ( e : MouseEvent ) => {
23
29
if (
24
30
openRef . current &&
25
- ! inPopupOrChild ( e . composedPath ?.( ) ?. [ 0 ] || e . target )
31
+ ! inPopupOrChild ( e . composedPath ?.( ) ?. [ 0 ] || e . target ) &&
32
+ ! popupPointerDownRef . current
26
33
) {
27
34
triggerOpen ( false ) ;
28
35
}
29
36
} ;
30
37
31
38
const win = getWin ( popupEle ) ;
32
39
40
+ win . addEventListener ( 'pointerdown' , onPointerDown , true ) ;
33
41
win . addEventListener ( 'mousedown' , onTriggerClose , true ) ;
34
42
win . addEventListener ( 'contextmenu' , onTriggerClose , true ) ;
35
43
@@ -52,6 +60,7 @@ export default function useWinClick(
52
60
}
53
61
54
62
return ( ) => {
63
+ win . removeEventListener ( 'pointerdown' , onPointerDown , true ) ;
55
64
win . removeEventListener ( 'mousedown' , onTriggerClose , true ) ;
56
65
win . removeEventListener ( 'contextmenu' , onTriggerClose , true ) ;
57
66
@@ -70,4 +79,10 @@ export default function useWinClick(
70
79
} ;
71
80
}
72
81
} , [ clickToHide , targetEle , popupEle , mask , maskClosable ] ) ;
82
+
83
+ function onPopupPointerDown ( ) {
84
+ popupPointerDownRef . current = true ;
85
+ }
86
+
87
+ return onPopupPointerDown ;
73
88
}
0 commit comments