@@ -17,17 +17,22 @@ import useWatch from './hooks/useWatch';
17
17
import type {
18
18
ActionType ,
19
19
AlignType ,
20
+ AnimationType ,
20
21
ArrowType ,
21
22
ArrowTypeOuter ,
22
- AnimationType ,
23
23
BuildInPlacements ,
24
24
TransitionNameType ,
25
25
} from './interface' ;
26
26
import Popup from './Popup' ;
27
27
import TriggerWrapper from './TriggerWrapper' ;
28
28
import { getAlignPopupClassName , getMotion , getWin } from './util' ;
29
29
30
- export type { BuildInPlacements , AlignType , ActionType , ArrowTypeOuter as ArrowType } ;
30
+ export type {
31
+ BuildInPlacements ,
32
+ AlignType ,
33
+ ActionType ,
34
+ ArrowTypeOuter as ArrowType ,
35
+ } ;
31
36
32
37
export interface TriggerRef {
33
38
forceAlign : VoidFunction ;
@@ -495,8 +500,16 @@ export function generateTrigger(
495
500
// Click to hide is special action since click popup element should not hide
496
501
React . useEffect ( ( ) => {
497
502
if ( clickToHide && popupEle && ( ! mask || maskClosable ) ) {
503
+ let clickInside = false ;
504
+
505
+ // User may mouseDown inside and drag out of popup and mouse up
506
+ // Record here to prevent close
507
+ const onWindowMouseDown = ( { target } : MouseEvent ) => {
508
+ clickInside = inPopupOrChild ( target ) ;
509
+ } ;
510
+
498
511
const onWindowClick = ( { target } : MouseEvent ) => {
499
- if ( openRef . current && ! inPopupOrChild ( target ) ) {
512
+ if ( openRef . current && ! clickInside && ! inPopupOrChild ( target ) ) {
500
513
triggerOpen ( false ) ;
501
514
}
502
515
} ;
@@ -505,11 +518,16 @@ export function generateTrigger(
505
518
506
519
const targetRoot = targetEle ?. getRootNode ( ) ;
507
520
521
+ win . addEventListener ( 'mousedown' , onWindowMouseDown ) ;
508
522
win . addEventListener ( 'click' , onWindowClick ) ;
509
523
510
524
// shadow root
511
525
const inShadow = targetRoot && targetRoot !== targetEle . ownerDocument ;
512
526
if ( inShadow ) {
527
+ ( targetRoot as ShadowRoot ) . addEventListener (
528
+ 'mousedown' ,
529
+ onWindowMouseDown ,
530
+ ) ;
513
531
( targetRoot as ShadowRoot ) . addEventListener ( 'click' , onWindowClick ) ;
514
532
}
515
533
@@ -524,9 +542,14 @@ export function generateTrigger(
524
542
}
525
543
526
544
return ( ) => {
545
+ win . removeEventListener ( 'mousedown' , onWindowMouseDown ) ;
527
546
win . removeEventListener ( 'click' , onWindowClick ) ;
528
547
529
548
if ( inShadow ) {
549
+ ( targetRoot as ShadowRoot ) . removeEventListener (
550
+ 'mousedown' ,
551
+ onWindowMouseDown ,
552
+ ) ;
530
553
( targetRoot as ShadowRoot ) . removeEventListener (
531
554
'click' ,
532
555
onWindowClick ,
@@ -627,12 +650,14 @@ export function generateTrigger(
627
650
...passedProps ,
628
651
} ) ;
629
652
630
- const innerArrow : ArrowType = arrow ? {
631
- // true and Object likely
632
- ...( arrow !== true ? arrow : { } ) ,
633
- x : arrowX ,
634
- y : arrowY
635
- } : null ;
653
+ const innerArrow : ArrowType = arrow
654
+ ? {
655
+ // true and Object likely
656
+ ...( arrow !== true ? arrow : { } ) ,
657
+ x : arrowX ,
658
+ y : arrowY ,
659
+ }
660
+ : null ;
636
661
637
662
// Render
638
663
return (
0 commit comments