Skip to content

Commit a12dd91

Browse files
committed
fix #45
1 parent da5bbc2 commit a12dd91

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rc-trigger",
3-
"version": "1.9.0",
3+
"version": "1.9.1",
44
"description": "base abstract trigger component for react",
55
"keywords": [
66
"react",

src/Trigger.jsx

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const Trigger = React.createClass({
7575
popupContainer.style.left = '0';
7676
popupContainer.style.width = '100%';
7777
const mountNode = props.getPopupContainer ?
78-
props.getPopupContainer(findDOMNode(instance)) : props.getDocument().body;
78+
props.getPopupContainer(findDOMNode(instance)) : props.getDocument().body;
7979
mountNode.appendChild(popupContainer);
8080
return popupContainer;
8181
},
@@ -150,34 +150,29 @@ const Trigger = React.createClass({
150150
props.afterPopupVisibleChange(state.popupVisible);
151151
}
152152
});
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);
163160
}
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;
164168
}
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();
171171
},
172172

173173
componentWillUnmount() {
174174
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();
181176
},
182177

183178
onMouseEnter(e) {
@@ -371,6 +366,18 @@ const Trigger = React.createClass({
371366
}
372367
},
373368

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+
374381
createTwoChains(event) {
375382
const childPros = this.props.children.props;
376383
const props = this.props;
@@ -435,7 +442,6 @@ const Trigger = React.createClass({
435442
const children = props.children;
436443
const child = React.Children.only(children);
437444
const newChildProps = {};
438-
439445
if (this.isClickToHide() || this.isClickToShow()) {
440446
newChildProps.onClick = this.onClick;
441447
newChildProps.onMouseDown = this.onMouseDown;

0 commit comments

Comments
 (0)