@@ -19,8 +19,7 @@ function returnDocument() {
19
19
return window . document ;
20
20
}
21
21
22
- // use fastclick for mobile touch
23
- const ALL_HANDLERS = [ 'onClick' , 'onMouseDown' , 'onMouseEnter' ,
22
+ const ALL_HANDLERS = [ 'onClick' , 'onMouseDown' , 'onTouchStart' , 'onMouseEnter' ,
24
23
'onMouseLeave' , 'onFocus' , 'onBlur' ] ;
25
24
26
25
const Trigger = createReactClass ( {
@@ -166,7 +165,13 @@ const Trigger = createReactClass({
166
165
if ( ! this . clickOutsideHandler && this . isClickToHide ( ) ) {
167
166
currentDocument = props . getDocument ( ) ;
168
167
this . clickOutsideHandler = addEventListener ( currentDocument ,
169
- 'click' , this . onDocumentClick ) ;
168
+ 'mousedown' , this . onDocumentClick ) ;
169
+ }
170
+ // always hide on mobile
171
+ if ( ! this . touchOutsideHandler ) {
172
+ currentDocument = currentDocument || props . getDocument ( ) ;
173
+ this . touchOutsideHandler = addEventListener ( currentDocument ,
174
+ 'touchstart' , this . onDocumentClick ) ;
170
175
}
171
176
return ;
172
177
}
@@ -219,6 +224,11 @@ const Trigger = createReactClass({
219
224
this . preClickTime = Date . now ( ) ;
220
225
} ,
221
226
227
+ onTouchStart ( e ) {
228
+ this . fireEvents ( 'onTouchStart' , e ) ;
229
+ this . preTouchTime = Date . now ( ) ;
230
+ } ,
231
+
222
232
onBlur ( e ) {
223
233
this . fireEvents ( 'onBlur' , e ) ;
224
234
this . clearDelayTimer ( ) ;
@@ -232,15 +242,20 @@ const Trigger = createReactClass({
232
242
// focus will trigger click
233
243
if ( this . focusTime ) {
234
244
let preTime ;
235
- if ( this . preClickTime ) {
245
+ if ( this . preClickTime && this . preTouchTime ) {
246
+ preTime = Math . min ( this . preClickTime , this . preTouchTime ) ;
247
+ } else if ( this . preClickTime ) {
236
248
preTime = this . preClickTime ;
249
+ } else if ( this . preTouchTime ) {
250
+ preTime = this . preTouchTime ;
237
251
}
238
252
if ( Math . abs ( preTime - this . focusTime ) < 20 ) {
239
253
return ;
240
254
}
241
255
this . focusTime = 0 ;
242
256
}
243
257
this . preClickTime = 0 ;
258
+ this . preTouchTime = 0 ;
244
259
event . preventDefault ( ) ;
245
260
const nextVisible = ! this . state . popupVisible ;
246
261
if ( this . isClickToHide ( ) && ! nextVisible || nextVisible && this . isClickToShow ( ) ) {
@@ -365,6 +380,11 @@ const Trigger = createReactClass({
365
380
this . clickOutsideHandler . remove ( ) ;
366
381
this . clickOutsideHandler = null ;
367
382
}
383
+
384
+ if ( this . touchOutsideHandler ) {
385
+ this . touchOutsideHandler . remove ( ) ;
386
+ this . touchOutsideHandler = null ;
387
+ }
368
388
} ,
369
389
370
390
createTwoChains ( event ) {
@@ -434,9 +454,11 @@ const Trigger = createReactClass({
434
454
if ( this . isClickToHide ( ) || this . isClickToShow ( ) ) {
435
455
newChildProps . onClick = this . onClick ;
436
456
newChildProps . onMouseDown = this . onMouseDown ;
457
+ newChildProps . onTouchStart = this . onTouchStart ;
437
458
} else {
438
459
newChildProps . onClick = this . createTwoChains ( 'onClick' ) ;
439
460
newChildProps . onMouseDown = this . createTwoChains ( 'onMouseDown' ) ;
461
+ newChildProps . onTouchStart = this . createTwoChains ( 'onTouchStart' ) ;
440
462
}
441
463
if ( this . isMouseEnterToShow ( ) ) {
442
464
newChildProps . onMouseEnter = this . onMouseEnter ;
0 commit comments