@@ -17,17 +17,22 @@ import useWatch from './hooks/useWatch';
1717import type {
1818 ActionType ,
1919 AlignType ,
20+ AnimationType ,
2021 ArrowType ,
2122 ArrowTypeOuter ,
22- AnimationType ,
2323 BuildInPlacements ,
2424 TransitionNameType ,
2525} from './interface' ;
2626import Popup from './Popup' ;
2727import TriggerWrapper from './TriggerWrapper' ;
2828import { getAlignPopupClassName , getMotion , getWin } from './util' ;
2929
30- export type { BuildInPlacements , AlignType , ActionType , ArrowTypeOuter as ArrowType } ;
30+ export type {
31+ BuildInPlacements ,
32+ AlignType ,
33+ ActionType ,
34+ ArrowTypeOuter as ArrowType ,
35+ } ;
3136
3237export interface TriggerRef {
3338 forceAlign : VoidFunction ;
@@ -495,8 +500,16 @@ export function generateTrigger(
495500 // Click to hide is special action since click popup element should not hide
496501 React . useEffect ( ( ) => {
497502 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+
498511 const onWindowClick = ( { target } : MouseEvent ) => {
499- if ( openRef . current && ! inPopupOrChild ( target ) ) {
512+ if ( openRef . current && ! clickInside && ! inPopupOrChild ( target ) ) {
500513 triggerOpen ( false ) ;
501514 }
502515 } ;
@@ -505,11 +518,16 @@ export function generateTrigger(
505518
506519 const targetRoot = targetEle ?. getRootNode ( ) ;
507520
521+ win . addEventListener ( 'mousedown' , onWindowMouseDown ) ;
508522 win . addEventListener ( 'click' , onWindowClick ) ;
509523
510524 // shadow root
511525 const inShadow = targetRoot && targetRoot !== targetEle . ownerDocument ;
512526 if ( inShadow ) {
527+ ( targetRoot as ShadowRoot ) . addEventListener (
528+ 'mousedown' ,
529+ onWindowMouseDown ,
530+ ) ;
513531 ( targetRoot as ShadowRoot ) . addEventListener ( 'click' , onWindowClick ) ;
514532 }
515533
@@ -524,9 +542,14 @@ export function generateTrigger(
524542 }
525543
526544 return ( ) => {
545+ win . removeEventListener ( 'mousedown' , onWindowMouseDown ) ;
527546 win . removeEventListener ( 'click' , onWindowClick ) ;
528547
529548 if ( inShadow ) {
549+ ( targetRoot as ShadowRoot ) . removeEventListener (
550+ 'mousedown' ,
551+ onWindowMouseDown ,
552+ ) ;
530553 ( targetRoot as ShadowRoot ) . removeEventListener (
531554 'click' ,
532555 onWindowClick ,
@@ -627,12 +650,14 @@ export function generateTrigger(
627650 ...passedProps ,
628651 } ) ;
629652
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 ;
636661
637662 // Render
638663 return (
0 commit comments