@@ -13,9 +13,16 @@ const isMobile =
1313 typeof navigator !== "undefined" &&
1414 ! ! navigator . userAgent . match ( / ( A n d r o i d | i P h o n e | i P a d | i P o d | i O S | U C W E B ) / i) ;
1515
16- type ActionType = "click" | "contextMenu" | "focus" | "hover" | "mouseDown" ;
17- type ShowActionType = "click" | "contextMenu" | "focus" | "mouseEnter" | "mouseDown" ;
18- type HideActionType = "click" | "mouseLeave" | "blur" | "resize" | "scroll" | "mouseDown" ;
16+ type ActionType = "click" | "contextMenu" | "focus" | "hover" | "mouseDown" | "mouseUp" ;
17+ type ShowActionType = "click" | "contextMenu" | "focus" | "mouseEnter" | "mouseDown" | "mouseUp" ;
18+ type HideActionType =
19+ | "click"
20+ | "mouseLeave"
21+ | "blur"
22+ | "resize"
23+ | "scroll"
24+ | "mouseDown"
25+ | "mouseUp" ;
1926type Delay = {
2027 show ?: number ;
2128 hide ?: number ;
@@ -53,8 +60,10 @@ export interface TriggerProps {
5360 /** 触发事件 */
5461 action ?: ActionType | ActionType [ ] | null ;
5562 /** 显示触发事件,同action合并 */
63+ // TODO: 只针对triggerNode?
5664 showAction ?: ShowActionType | ShowActionType [ ] | null ;
5765 /** 隐藏触发事件,同action合并 */
66+ // TODO: 只针对Outside?
5867 hideAction ?: HideActionType | HideActionType [ ] | null ;
5968 /** 显示/隐藏延迟时间 */
6069 delay ?: number | Delay ;
@@ -204,15 +213,20 @@ export class Trigger extends React.Component<TriggerProps, TriggerState> {
204213
205214 if (
206215 ! this . clickOutsideHandler &&
207- ( this . isMouseDownToHide ( ) || this . isClickToHide ( ) || this . isContextMenuToShow ( ) )
216+ ( this . isMouseDownToHide ( ) ||
217+ this . isMouseUpToHide ( ) ||
218+ this . isClickToHide ( ) ||
219+ this . isContextMenuToShow ( ) )
208220 ) {
209- this . clickOutsideHandler = listen ( currentDocument , "mousedown" , ( e ) => {
210- this . onDocumentClick ( e ) ;
211- } ) ;
221+ this . clickOutsideHandler = listen (
222+ currentDocument ,
223+ "mousedown" ,
224+ this . onOutsideClick
225+ ) ;
212226 }
213227
214228 if ( ! this . touchOutsideHandler && isMobile ) {
215- this . touchOutsideHandler = listen ( currentDocument , "click" , this . onDocumentClick ) ;
229+ this . touchOutsideHandler = listen ( currentDocument , "click" , this . onOutsideClick ) ;
216230 }
217231
218232 // close popup when trigger type contains 'onContextMenu' and document is scrolling.
@@ -230,7 +244,7 @@ export class Trigger extends React.Component<TriggerProps, TriggerState> {
230244 }
231245
232246 if ( ! this . windowScrollHandler && this . isWindowScrollToHide ( ) ) {
233- this . windowScrollHandler = listen ( currentDocument , "scroll" , this . onDocumentClick ) ;
247+ this . windowScrollHandler = listen ( currentDocument , "scroll" , this . onOutsideClick ) ;
234248 }
235249
236250 if ( ! this . windowResizeHandler && this . isWindowResizeToHide ( ) ) {
@@ -254,7 +268,7 @@ export class Trigger extends React.Component<TriggerProps, TriggerState> {
254268 return findDOMNode ( this ) as HTMLElement ;
255269 }
256270
257- protected onDocumentClick = ( event : MouseEvent ) => {
271+ protected onOutsideClick = ( event : MouseEvent ) => {
258272 const target = event . target as Element ;
259273 const triggerNode = this . getTriggerNode ( ) ;
260274 const popupRootNode = this . popupInstance . getRootDOM ( ) ;
@@ -396,6 +410,14 @@ export class Trigger extends React.Component<TriggerProps, TriggerState> {
396410 return this . checkToHide ( [ "mouseDown" ] ) ;
397411 }
398412
413+ protected isMouseUpToShow ( ) {
414+ return this . checkToShow ( [ "mouseUp" ] ) ;
415+ }
416+
417+ protected isMouseUpToHide ( ) {
418+ return this . checkToHide ( [ "mouseUp" ] ) ;
419+ }
420+
399421 protected isClickToShow ( ) {
400422 return this . checkToShow ( [ "click" ] ) ;
401423 }
@@ -452,6 +474,14 @@ export class Trigger extends React.Component<TriggerProps, TriggerState> {
452474 }
453475 }
454476
477+ protected onTriggerMouseUp ( e : React . MouseEvent ) {
478+ const nextVisible = ! this . state . popupVisible ;
479+
480+ if ( ( this . isMouseUpToHide ( ) && ! nextVisible ) || ( nextVisible && this . isMouseUpToShow ( ) ) ) {
481+ this . delaySetPopupVisible ( nextVisible ) ;
482+ }
483+ }
484+
455485 protected onMouseEnter = ( e : React . MouseEvent ) => {
456486 this . delaySetPopupVisible ( true ) ;
457487 } ;
@@ -672,6 +702,20 @@ export class Trigger extends React.Component<TriggerProps, TriggerState> {
672702 } ;
673703 }
674704
705+ if ( this . isMouseUpToShow ( ) || this . isMouseUpToHide ( ) ) {
706+ newChildProps . onMouseUp = ( e ) => {
707+ if ( child . props . onMouseUp ) {
708+ child . props . onMouseUp ( e ) ;
709+ }
710+
711+ if ( checkDefaultPrevented && e . defaultPrevented ) return ;
712+
713+ this . clearDelayTimer ( ) ;
714+
715+ this . onTriggerMouseUp ( e ) ;
716+ } ;
717+ }
718+
675719 if ( this . isClickToHide ( ) || this . isClickToShow ( ) ) {
676720 newChildProps . onClick = ( e ) => {
677721 if ( child . props . onClick ) {
0 commit comments