@@ -13,9 +13,16 @@ const isMobile =
13
13
typeof navigator !== "undefined" &&
14
14
! ! 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) ;
15
15
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" ;
19
26
type Delay = {
20
27
show ?: number ;
21
28
hide ?: number ;
@@ -53,8 +60,10 @@ export interface TriggerProps {
53
60
/** 触发事件 */
54
61
action ?: ActionType | ActionType [ ] | null ;
55
62
/** 显示触发事件,同action合并 */
63
+ // TODO: 只针对triggerNode?
56
64
showAction ?: ShowActionType | ShowActionType [ ] | null ;
57
65
/** 隐藏触发事件,同action合并 */
66
+ // TODO: 只针对Outside?
58
67
hideAction ?: HideActionType | HideActionType [ ] | null ;
59
68
/** 显示/隐藏延迟时间 */
60
69
delay ?: number | Delay ;
@@ -204,15 +213,20 @@ export class Trigger extends React.Component<TriggerProps, TriggerState> {
204
213
205
214
if (
206
215
! this . clickOutsideHandler &&
207
- ( this . isMouseDownToHide ( ) || this . isClickToHide ( ) || this . isContextMenuToShow ( ) )
216
+ ( this . isMouseDownToHide ( ) ||
217
+ this . isMouseUpToHide ( ) ||
218
+ this . isClickToHide ( ) ||
219
+ this . isContextMenuToShow ( ) )
208
220
) {
209
- this . clickOutsideHandler = listen ( currentDocument , "mousedown" , ( e ) => {
210
- this . onDocumentClick ( e ) ;
211
- } ) ;
221
+ this . clickOutsideHandler = listen (
222
+ currentDocument ,
223
+ "mousedown" ,
224
+ this . onOutsideClick
225
+ ) ;
212
226
}
213
227
214
228
if ( ! this . touchOutsideHandler && isMobile ) {
215
- this . touchOutsideHandler = listen ( currentDocument , "click" , this . onDocumentClick ) ;
229
+ this . touchOutsideHandler = listen ( currentDocument , "click" , this . onOutsideClick ) ;
216
230
}
217
231
218
232
// close popup when trigger type contains 'onContextMenu' and document is scrolling.
@@ -230,7 +244,7 @@ export class Trigger extends React.Component<TriggerProps, TriggerState> {
230
244
}
231
245
232
246
if ( ! this . windowScrollHandler && this . isWindowScrollToHide ( ) ) {
233
- this . windowScrollHandler = listen ( currentDocument , "scroll" , this . onDocumentClick ) ;
247
+ this . windowScrollHandler = listen ( currentDocument , "scroll" , this . onOutsideClick ) ;
234
248
}
235
249
236
250
if ( ! this . windowResizeHandler && this . isWindowResizeToHide ( ) ) {
@@ -254,7 +268,7 @@ export class Trigger extends React.Component<TriggerProps, TriggerState> {
254
268
return findDOMNode ( this ) as HTMLElement ;
255
269
}
256
270
257
- protected onDocumentClick = ( event : MouseEvent ) => {
271
+ protected onOutsideClick = ( event : MouseEvent ) => {
258
272
const target = event . target as Element ;
259
273
const triggerNode = this . getTriggerNode ( ) ;
260
274
const popupRootNode = this . popupInstance . getRootDOM ( ) ;
@@ -396,6 +410,14 @@ export class Trigger extends React.Component<TriggerProps, TriggerState> {
396
410
return this . checkToHide ( [ "mouseDown" ] ) ;
397
411
}
398
412
413
+ protected isMouseUpToShow ( ) {
414
+ return this . checkToShow ( [ "mouseUp" ] ) ;
415
+ }
416
+
417
+ protected isMouseUpToHide ( ) {
418
+ return this . checkToHide ( [ "mouseUp" ] ) ;
419
+ }
420
+
399
421
protected isClickToShow ( ) {
400
422
return this . checkToShow ( [ "click" ] ) ;
401
423
}
@@ -452,6 +474,14 @@ export class Trigger extends React.Component<TriggerProps, TriggerState> {
452
474
}
453
475
}
454
476
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
+
455
485
protected onMouseEnter = ( e : React . MouseEvent ) => {
456
486
this . delaySetPopupVisible ( true ) ;
457
487
} ;
@@ -672,6 +702,20 @@ export class Trigger extends React.Component<TriggerProps, TriggerState> {
672
702
} ;
673
703
}
674
704
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
+
675
719
if ( this . isClickToHide ( ) || this . isClickToShow ( ) ) {
676
720
newChildProps . onClick = ( e ) => {
677
721
if ( child . props . onClick ) {
0 commit comments