Skip to content

Commit

Permalink
use click. Fixes #49
Browse files Browse the repository at this point in the history
  • Loading branch information
yiminghe committed Apr 13, 2017
1 parent 734b81e commit b9bb160
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rc-trigger",
"version": "1.9.1",
"version": "1.10.0",
"description": "base abstract trigger component for react",
"keywords": [
"react",
Expand Down
30 changes: 4 additions & 26 deletions src/Trigger.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ function returnDocument() {
return window.document;
}

const ALL_HANDLERS = ['onClick', 'onMouseDown', 'onTouchStart', 'onMouseEnter',
// use fastclick for mobile touch
const ALL_HANDLERS = ['onClick', 'onMouseDown', 'onMouseEnter',
'onMouseLeave', 'onFocus', 'onBlur'];

const Trigger = React.createClass({
Expand Down Expand Up @@ -162,13 +163,7 @@ const Trigger = React.createClass({
if (!this.clickOutsideHandler && this.isClickToHide()) {
currentDocument = props.getDocument();
this.clickOutsideHandler = addEventListener(currentDocument,
'mousedown', this.onDocumentClick);
}
// always hide on mobile
if (!this.touchOutsideHandler) {
currentDocument = currentDocument || props.getDocument();
this.touchOutsideHandler = addEventListener(currentDocument,
'touchstart', this.onDocumentClick);
'click', this.onDocumentClick);
}
return;
}
Expand Down Expand Up @@ -221,11 +216,6 @@ const Trigger = React.createClass({
this.preClickTime = Date.now();
},

onTouchStart(e) {
this.fireEvents('onTouchStart', e);
this.preTouchTime = Date.now();
},

onBlur(e) {
this.fireEvents('onBlur', e);
this.clearDelayTimer();
Expand All @@ -239,20 +229,15 @@ const Trigger = React.createClass({
// focus will trigger click
if (this.focusTime) {
let preTime;
if (this.preClickTime && this.preTouchTime) {
preTime = Math.min(this.preClickTime, this.preTouchTime);
} else if (this.preClickTime) {
if (this.preClickTime) {
preTime = this.preClickTime;
} else if (this.preTouchTime) {
preTime = this.preTouchTime;
}
if (Math.abs(preTime - this.focusTime) < 20) {
return;
}
this.focusTime = 0;
}
this.preClickTime = 0;
this.preTouchTime = 0;
event.preventDefault();
const nextVisible = !this.state.popupVisible;
if (this.isClickToHide() && !nextVisible || nextVisible && this.isClickToShow()) {
Expand Down Expand Up @@ -377,11 +362,6 @@ const Trigger = React.createClass({
this.clickOutsideHandler.remove();
this.clickOutsideHandler = null;
}

if (this.touchOutsideHandler) {
this.touchOutsideHandler.remove();
this.touchOutsideHandler = null;
}
},

createTwoChains(event) {
Expand Down Expand Up @@ -451,11 +431,9 @@ const Trigger = React.createClass({
if (this.isClickToHide() || this.isClickToShow()) {
newChildProps.onClick = this.onClick;
newChildProps.onMouseDown = this.onMouseDown;
newChildProps.onTouchStart = this.onTouchStart;
} else {
newChildProps.onClick = this.createTwoChains('onClick');
newChildProps.onMouseDown = this.createTwoChains('onMouseDown');
newChildProps.onTouchStart = this.createTwoChains('onTouchStart');
}
if (this.isMouseEnterToShow()) {
newChildProps.onMouseEnter = this.onMouseEnter;
Expand Down

0 comments on commit b9bb160

Please sign in to comment.