@@ -75,7 +75,7 @@ const Trigger = React.createClass({
75
75
popupContainer . style . left = '0' ;
76
76
popupContainer . style . width = '100%' ;
77
77
const mountNode = props . getPopupContainer ?
78
- props . getPopupContainer ( findDOMNode ( instance ) ) : props . getDocument ( ) . body ;
78
+ props . getPopupContainer ( findDOMNode ( instance ) ) : props . getDocument ( ) . body ;
79
79
mountNode . appendChild ( popupContainer ) ;
80
80
return popupContainer ;
81
81
} ,
@@ -150,34 +150,29 @@ const Trigger = React.createClass({
150
150
props . afterPopupVisibleChange ( state . popupVisible ) ;
151
151
}
152
152
} ) ;
153
- if ( this . isClickToHide ( ) ) {
154
- if ( state . popupVisible ) {
155
- if ( ! this . clickOutsideHandler ) {
156
- const currentDocument = props . getDocument ( ) ;
157
- this . clickOutsideHandler = addEventListener ( currentDocument ,
158
- 'mousedown' , this . onDocumentClick ) ;
159
- this . touchOutsideHandler = addEventListener ( currentDocument ,
160
- 'touchstart' , this . onDocumentClick ) ;
161
- }
162
- return ;
153
+
154
+ if ( state . popupVisible ) {
155
+ let currentDocument ;
156
+ if ( ! this . clickOutsideHandler && this . isClickToHide ( ) ) {
157
+ currentDocument = props . getDocument ( ) ;
158
+ this . clickOutsideHandler = addEventListener ( currentDocument ,
159
+ 'mousedown' , this . onDocumentClick ) ;
163
160
}
161
+ // always hide on mobile
162
+ if ( ! this . touchOutsideHandler ) {
163
+ currentDocument = currentDocument || props . getDocument ( ) ;
164
+ this . touchOutsideHandler = addEventListener ( currentDocument ,
165
+ 'touchstart' , this . onDocumentClick ) ;
166
+ }
167
+ return ;
164
168
}
165
- if ( this . clickOutsideHandler ) {
166
- this . clickOutsideHandler . remove ( ) ;
167
- this . touchOutsideHandler . remove ( ) ;
168
- this . clickOutsideHandler = null ;
169
- this . touchOutsideHandler = null ;
170
- }
169
+
170
+ this . clearOutsideHandler ( ) ;
171
171
} ,
172
172
173
173
componentWillUnmount ( ) {
174
174
this . clearDelayTimer ( ) ;
175
- if ( this . clickOutsideHandler ) {
176
- this . clickOutsideHandler . remove ( ) ;
177
- this . touchOutsideHandler . remove ( ) ;
178
- this . clickOutsideHandler = null ;
179
- this . touchOutsideHandler = null ;
180
- }
175
+ this . clearOutsideHandler ( ) ;
181
176
} ,
182
177
183
178
onMouseEnter ( e ) {
@@ -371,6 +366,18 @@ const Trigger = React.createClass({
371
366
}
372
367
} ,
373
368
369
+ clearOutsideHandler ( ) {
370
+ if ( this . clickOutsideHandler ) {
371
+ this . clickOutsideHandler . remove ( ) ;
372
+ this . clickOutsideHandler = null ;
373
+ }
374
+
375
+ if ( this . touchOutsideHandler ) {
376
+ this . touchOutsideHandler . remove ( ) ;
377
+ this . touchOutsideHandler = null ;
378
+ }
379
+ } ,
380
+
374
381
createTwoChains ( event ) {
375
382
const childPros = this . props . children . props ;
376
383
const props = this . props ;
@@ -435,7 +442,6 @@ const Trigger = React.createClass({
435
442
const children = props . children ;
436
443
const child = React . Children . only ( children ) ;
437
444
const newChildProps = { } ;
438
-
439
445
if ( this . isClickToHide ( ) || this . isClickToShow ( ) ) {
440
446
newChildProps . onClick = this . onClick ;
441
447
newChildProps . onMouseDown = this . onMouseDown ;
0 commit comments