@@ -7,7 +7,10 @@ import addEventListener from 'rc-util/lib/Dom/addEventListener';
77import Portal from 'rc-util/lib/Portal' ;
88import classNames from 'classnames' ;
99
10- import { getAlignFromPlacement , getAlignPopupClassName } from './utils/alignUtil' ;
10+ import {
11+ getAlignFromPlacement ,
12+ getAlignPopupClassName ,
13+ } from './utils/alignUtil' ;
1114import Popup from './Popup' ;
1215import TriggerContext from './context' ;
1316import {
@@ -106,7 +109,9 @@ interface TriggerState {
106109/**
107110 * Internal usage. Do not use in your code since this will be removed.
108111 */
109- export function generateTrigger ( PortalComponent : any ) : React . ComponentClass < TriggerProps > {
112+ export function generateTrigger (
113+ PortalComponent : any ,
114+ ) : React . ComponentClass < TriggerProps > {
110115 class Trigger extends React . Component < TriggerProps , TriggerState > {
111116 static contextType = TriggerContext ;
112117
@@ -193,7 +198,10 @@ export function generateTrigger(PortalComponent: any): React.ComponentClass<Trig
193198 // https://github.com/react-component/trigger/issues/50
194199 if ( state . popupVisible ) {
195200 let currentDocument ;
196- if ( ! this . clickOutsideHandler && ( this . isClickToHide ( ) || this . isContextMenuToShow ( ) ) ) {
201+ if (
202+ ! this . clickOutsideHandler &&
203+ ( this . isClickToHide ( ) || this . isContextMenuToShow ( ) )
204+ ) {
197205 currentDocument = props . getDocument ( ) ;
198206 this . clickOutsideHandler = addEventListener (
199207 currentDocument ,
@@ -242,7 +250,11 @@ export function generateTrigger(PortalComponent: any): React.ComponentClass<Trig
242250 onMouseEnter = e => {
243251 const { mouseEnterDelay } = this . props ;
244252 this . fireEvents ( 'onMouseEnter' , e ) ;
245- this . delaySetPopupVisible ( true , mouseEnterDelay , mouseEnterDelay ? null : e ) ;
253+ this . delaySetPopupVisible (
254+ true ,
255+ mouseEnterDelay ,
256+ mouseEnterDelay ? null : e ,
257+ ) ;
246258 } ;
247259
248260 onMouseMove = e => {
@@ -346,7 +358,10 @@ export function generateTrigger(PortalComponent: any): React.ComponentClass<Trig
346358 event . preventDefault ( ) ;
347359 }
348360 const nextVisible = ! this . state . popupVisible ;
349- if ( ( this . isClickToHide ( ) && ! nextVisible ) || ( nextVisible && this . isClickToShow ( ) ) ) {
361+ if (
362+ ( this . isClickToHide ( ) && ! nextVisible ) ||
363+ ( nextVisible && this . isClickToShow ( ) )
364+ ) {
350365 this . setPopupVisible ( ! this . state . popupVisible , event ) ;
351366 }
352367 } ;
@@ -371,15 +386,26 @@ export function generateTrigger(PortalComponent: any): React.ComponentClass<Trig
371386
372387 const { target } = event ;
373388 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+ ) {
375395 this . close ( ) ;
376396 }
377397 } ;
378398
379- static getDerivedStateFromProps ( { popupVisible } : TriggerProps , prevState : TriggerState ) {
399+ static getDerivedStateFromProps (
400+ { popupVisible } : TriggerProps ,
401+ prevState : TriggerState ,
402+ ) {
380403 const newState : Partial < TriggerState > = { } ;
381404
382- if ( popupVisible !== undefined && prevState . popupVisible !== popupVisible ) {
405+ if (
406+ popupVisible !== undefined &&
407+ prevState . popupVisible !== popupVisible
408+ ) {
383409 newState . popupVisible = popupVisible ;
384410 newState . prevPopupVisible = prevState . popupVisible ;
385411 }
@@ -423,7 +449,14 @@ export function generateTrigger(PortalComponent: any): React.ComponentClass<Trig
423449 getPopupClassNameFromAlign,
424450 } = this . props ;
425451 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+ ) ;
427460 }
428461 if ( getPopupClassNameFromAlign ) {
429462 className . push ( getPopupClassNameFromAlign ( align ) ) ;
@@ -435,7 +468,11 @@ export function generateTrigger(PortalComponent: any): React.ComponentClass<Trig
435468 const { props } = this ;
436469 const { popupPlacement, popupAlign, builtinPlacements } = props ;
437470 if ( popupPlacement && builtinPlacements ) {
438- return getAlignFromPlacement ( builtinPlacements , popupPlacement , popupAlign ) ;
471+ return getAlignFromPlacement (
472+ builtinPlacements ,
473+ popupPlacement ,
474+ popupAlign ,
475+ ) ;
439476 }
440477 return popupAlign ;
441478 }
@@ -614,37 +651,54 @@ export function generateTrigger(PortalComponent: any): React.ComponentClass<Trig
614651
615652 isClickToShow ( ) {
616653 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+ ) ;
618657 }
619658
620659 isContextMenuToShow ( ) {
621660 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+ ) ;
623665 }
624666
625667 isClickToHide ( ) {
626668 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+ ) ;
628672 }
629673
630674 isMouseEnterToShow ( ) {
631675 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+ ) ;
633680 }
634681
635682 isMouseLeaveToHide ( ) {
636683 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+ ) ;
638688 }
639689
640690 isFocusToShow ( ) {
641691 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+ ) ;
643695 }
644696
645697 isBlurToHide ( ) {
646698 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+ ) ;
648702 }
649703
650704 forcePopupAlign ( ) {
@@ -658,7 +712,9 @@ export function generateTrigger(PortalComponent: any): React.ComponentClass<Trig
658712 }
659713
660714 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+ ] ;
662718 if ( childCallback ) {
663719 childCallback ( e ) ;
664720 }
@@ -676,7 +732,9 @@ export function generateTrigger(PortalComponent: any): React.ComponentClass<Trig
676732 const { popupVisible } = this . state ;
677733 const { children, forceRender, alignPoint, className } = this . props ;
678734 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+ } ;
680738
681739 if ( this . isContextMenuToShow ( ) ) {
682740 newChildProps . onContextMenu = this . onContextMenu ;
@@ -741,7 +799,9 @@ export function generateTrigger(PortalComponent: any): React.ComponentClass<Trig
741799 }
742800
743801 return (
744- < TriggerContext . Provider value = { { onPopupMouseDown : this . onPopupMouseDown } } >
802+ < TriggerContext . Provider
803+ value = { { onPopupMouseDown : this . onPopupMouseDown } }
804+ >
745805 { trigger }
746806 { portal }
747807 </ TriggerContext . Provider >
0 commit comments