@@ -7,7 +7,10 @@ import addEventListener from 'rc-util/lib/Dom/addEventListener';
7
7
import Portal from 'rc-util/lib/Portal' ;
8
8
import classNames from 'classnames' ;
9
9
10
- import { getAlignFromPlacement , getAlignPopupClassName } from './utils/alignUtil' ;
10
+ import {
11
+ getAlignFromPlacement ,
12
+ getAlignPopupClassName ,
13
+ } from './utils/alignUtil' ;
11
14
import Popup from './Popup' ;
12
15
import TriggerContext from './context' ;
13
16
import {
@@ -106,7 +109,9 @@ interface TriggerState {
106
109
/**
107
110
* Internal usage. Do not use in your code since this will be removed.
108
111
*/
109
- export function generateTrigger ( PortalComponent : any ) : React . ComponentClass < TriggerProps > {
112
+ export function generateTrigger (
113
+ PortalComponent : any ,
114
+ ) : React . ComponentClass < TriggerProps > {
110
115
class Trigger extends React . Component < TriggerProps , TriggerState > {
111
116
static contextType = TriggerContext ;
112
117
@@ -193,7 +198,10 @@ export function generateTrigger(PortalComponent: any): React.ComponentClass<Trig
193
198
// https://github.com/react-component/trigger/issues/50
194
199
if ( state . popupVisible ) {
195
200
let currentDocument ;
196
- if ( ! this . clickOutsideHandler && ( this . isClickToHide ( ) || this . isContextMenuToShow ( ) ) ) {
201
+ if (
202
+ ! this . clickOutsideHandler &&
203
+ ( this . isClickToHide ( ) || this . isContextMenuToShow ( ) )
204
+ ) {
197
205
currentDocument = props . getDocument ( ) ;
198
206
this . clickOutsideHandler = addEventListener (
199
207
currentDocument ,
@@ -242,7 +250,11 @@ export function generateTrigger(PortalComponent: any): React.ComponentClass<Trig
242
250
onMouseEnter = e => {
243
251
const { mouseEnterDelay } = this . props ;
244
252
this . fireEvents ( 'onMouseEnter' , e ) ;
245
- this . delaySetPopupVisible ( true , mouseEnterDelay , mouseEnterDelay ? null : e ) ;
253
+ this . delaySetPopupVisible (
254
+ true ,
255
+ mouseEnterDelay ,
256
+ mouseEnterDelay ? null : e ,
257
+ ) ;
246
258
} ;
247
259
248
260
onMouseMove = e => {
@@ -346,7 +358,10 @@ export function generateTrigger(PortalComponent: any): React.ComponentClass<Trig
346
358
event . preventDefault ( ) ;
347
359
}
348
360
const nextVisible = ! this . state . popupVisible ;
349
- if ( ( this . isClickToHide ( ) && ! nextVisible ) || ( nextVisible && this . isClickToShow ( ) ) ) {
361
+ if (
362
+ ( this . isClickToHide ( ) && ! nextVisible ) ||
363
+ ( nextVisible && this . isClickToShow ( ) )
364
+ ) {
350
365
this . setPopupVisible ( ! this . state . popupVisible , event ) ;
351
366
}
352
367
} ;
@@ -371,15 +386,26 @@ export function generateTrigger(PortalComponent: any): React.ComponentClass<Trig
371
386
372
387
const { target } = event ;
373
388
const root = this . getRootDomNode ( ) ;
374
- if ( ! contains ( root , target ) && ! this . hasPopupMouseDown ) {
389
+ const popupNode = this . getPopupDomNode ( ) ;
390
+ if (
391
+ ! contains ( root , target ) &&
392
+ ! contains ( popupNode , target ) &&
393
+ ! this . hasPopupMouseDown
394
+ ) {
375
395
this . close ( ) ;
376
396
}
377
397
} ;
378
398
379
- static getDerivedStateFromProps ( { popupVisible } : TriggerProps , prevState : TriggerState ) {
399
+ static getDerivedStateFromProps (
400
+ { popupVisible } : TriggerProps ,
401
+ prevState : TriggerState ,
402
+ ) {
380
403
const newState : Partial < TriggerState > = { } ;
381
404
382
- if ( popupVisible !== undefined && prevState . popupVisible !== popupVisible ) {
405
+ if (
406
+ popupVisible !== undefined &&
407
+ prevState . popupVisible !== popupVisible
408
+ ) {
383
409
newState . popupVisible = popupVisible ;
384
410
newState . prevPopupVisible = prevState . popupVisible ;
385
411
}
@@ -423,7 +449,14 @@ export function generateTrigger(PortalComponent: any): React.ComponentClass<Trig
423
449
getPopupClassNameFromAlign,
424
450
} = this . props ;
425
451
if ( popupPlacement && builtinPlacements ) {
426
- className . push ( getAlignPopupClassName ( builtinPlacements , prefixCls , align , alignPoint ) ) ;
452
+ className . push (
453
+ getAlignPopupClassName (
454
+ builtinPlacements ,
455
+ prefixCls ,
456
+ align ,
457
+ alignPoint ,
458
+ ) ,
459
+ ) ;
427
460
}
428
461
if ( getPopupClassNameFromAlign ) {
429
462
className . push ( getPopupClassNameFromAlign ( align ) ) ;
@@ -435,7 +468,11 @@ export function generateTrigger(PortalComponent: any): React.ComponentClass<Trig
435
468
const { props } = this ;
436
469
const { popupPlacement, popupAlign, builtinPlacements } = props ;
437
470
if ( popupPlacement && builtinPlacements ) {
438
- return getAlignFromPlacement ( builtinPlacements , popupPlacement , popupAlign ) ;
471
+ return getAlignFromPlacement (
472
+ builtinPlacements ,
473
+ popupPlacement ,
474
+ popupAlign ,
475
+ ) ;
439
476
}
440
477
return popupAlign ;
441
478
}
@@ -614,37 +651,54 @@ export function generateTrigger(PortalComponent: any): React.ComponentClass<Trig
614
651
615
652
isClickToShow ( ) {
616
653
const { action, showAction } = this . props ;
617
- return action . indexOf ( 'click' ) !== - 1 || showAction . indexOf ( 'click' ) !== - 1 ;
654
+ return (
655
+ action . indexOf ( 'click' ) !== - 1 || showAction . indexOf ( 'click' ) !== - 1
656
+ ) ;
618
657
}
619
658
620
659
isContextMenuToShow ( ) {
621
660
const { action, showAction } = this . props ;
622
- return action . indexOf ( 'contextMenu' ) !== - 1 || showAction . indexOf ( 'contextMenu' ) !== - 1 ;
661
+ return (
662
+ action . indexOf ( 'contextMenu' ) !== - 1 ||
663
+ showAction . indexOf ( 'contextMenu' ) !== - 1
664
+ ) ;
623
665
}
624
666
625
667
isClickToHide ( ) {
626
668
const { action, hideAction } = this . props ;
627
- return action . indexOf ( 'click' ) !== - 1 || hideAction . indexOf ( 'click' ) !== - 1 ;
669
+ return (
670
+ action . indexOf ( 'click' ) !== - 1 || hideAction . indexOf ( 'click' ) !== - 1
671
+ ) ;
628
672
}
629
673
630
674
isMouseEnterToShow ( ) {
631
675
const { action, showAction } = this . props ;
632
- return action . indexOf ( 'hover' ) !== - 1 || showAction . indexOf ( 'mouseEnter' ) !== - 1 ;
676
+ return (
677
+ action . indexOf ( 'hover' ) !== - 1 ||
678
+ showAction . indexOf ( 'mouseEnter' ) !== - 1
679
+ ) ;
633
680
}
634
681
635
682
isMouseLeaveToHide ( ) {
636
683
const { action, hideAction } = this . props ;
637
- return action . indexOf ( 'hover' ) !== - 1 || hideAction . indexOf ( 'mouseLeave' ) !== - 1 ;
684
+ return (
685
+ action . indexOf ( 'hover' ) !== - 1 ||
686
+ hideAction . indexOf ( 'mouseLeave' ) !== - 1
687
+ ) ;
638
688
}
639
689
640
690
isFocusToShow ( ) {
641
691
const { action, showAction } = this . props ;
642
- return action . indexOf ( 'focus' ) !== - 1 || showAction . indexOf ( 'focus' ) !== - 1 ;
692
+ return (
693
+ action . indexOf ( 'focus' ) !== - 1 || showAction . indexOf ( 'focus' ) !== - 1
694
+ ) ;
643
695
}
644
696
645
697
isBlurToHide ( ) {
646
698
const { action, hideAction } = this . props ;
647
- return action . indexOf ( 'focus' ) !== - 1 || hideAction . indexOf ( 'blur' ) !== - 1 ;
699
+ return (
700
+ action . indexOf ( 'focus' ) !== - 1 || hideAction . indexOf ( 'blur' ) !== - 1
701
+ ) ;
648
702
}
649
703
650
704
forcePopupAlign ( ) {
@@ -658,7 +712,9 @@ export function generateTrigger(PortalComponent: any): React.ComponentClass<Trig
658
712
}
659
713
660
714
fireEvents ( type : string , e : Event ) {
661
- const childCallback = ( this . props . children as React . ReactElement ) . props [ type ] ;
715
+ const childCallback = ( this . props . children as React . ReactElement ) . props [
716
+ type
717
+ ] ;
662
718
if ( childCallback ) {
663
719
childCallback ( e ) ;
664
720
}
@@ -676,7 +732,9 @@ export function generateTrigger(PortalComponent: any): React.ComponentClass<Trig
676
732
const { popupVisible } = this . state ;
677
733
const { children, forceRender, alignPoint, className } = this . props ;
678
734
const child = React . Children . only ( children ) as React . ReactElement ;
679
- const newChildProps : HTMLAttributes < HTMLElement > & { key : string } = { key : 'trigger' } ;
735
+ const newChildProps : HTMLAttributes < HTMLElement > & { key : string } = {
736
+ key : 'trigger' ,
737
+ } ;
680
738
681
739
if ( this . isContextMenuToShow ( ) ) {
682
740
newChildProps . onContextMenu = this . onContextMenu ;
@@ -741,7 +799,9 @@ export function generateTrigger(PortalComponent: any): React.ComponentClass<Trig
741
799
}
742
800
743
801
return (
744
- < TriggerContext . Provider value = { { onPopupMouseDown : this . onPopupMouseDown } } >
802
+ < TriggerContext . Provider
803
+ value = { { onPopupMouseDown : this . onPopupMouseDown } }
804
+ >
745
805
{ trigger }
746
806
{ portal }
747
807
</ TriggerContext . Provider >
0 commit comments