Skip to content

Commit b9bb160

Browse files
committed
use click. Fixes #49
1 parent 734b81e commit b9bb160

File tree

2 files changed

+5
-27
lines changed

2 files changed

+5
-27
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.1",
3+
"version": "1.10.0",
44
"description": "base abstract trigger component for react",
55
"keywords": [
66
"react",

src/Trigger.jsx

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ function returnDocument() {
1717
return window.document;
1818
}
1919

20-
const ALL_HANDLERS = ['onClick', 'onMouseDown', 'onTouchStart', 'onMouseEnter',
20+
// use fastclick for mobile touch
21+
const ALL_HANDLERS = ['onClick', 'onMouseDown', 'onMouseEnter',
2122
'onMouseLeave', 'onFocus', 'onBlur'];
2223

2324
const Trigger = React.createClass({
@@ -162,13 +163,7 @@ const Trigger = React.createClass({
162163
if (!this.clickOutsideHandler && this.isClickToHide()) {
163164
currentDocument = props.getDocument();
164165
this.clickOutsideHandler = addEventListener(currentDocument,
165-
'mousedown', this.onDocumentClick);
166-
}
167-
// always hide on mobile
168-
if (!this.touchOutsideHandler) {
169-
currentDocument = currentDocument || props.getDocument();
170-
this.touchOutsideHandler = addEventListener(currentDocument,
171-
'touchstart', this.onDocumentClick);
166+
'click', this.onDocumentClick);
172167
}
173168
return;
174169
}
@@ -221,11 +216,6 @@ const Trigger = React.createClass({
221216
this.preClickTime = Date.now();
222217
},
223218

224-
onTouchStart(e) {
225-
this.fireEvents('onTouchStart', e);
226-
this.preTouchTime = Date.now();
227-
},
228-
229219
onBlur(e) {
230220
this.fireEvents('onBlur', e);
231221
this.clearDelayTimer();
@@ -239,20 +229,15 @@ const Trigger = React.createClass({
239229
// focus will trigger click
240230
if (this.focusTime) {
241231
let preTime;
242-
if (this.preClickTime && this.preTouchTime) {
243-
preTime = Math.min(this.preClickTime, this.preTouchTime);
244-
} else if (this.preClickTime) {
232+
if (this.preClickTime) {
245233
preTime = this.preClickTime;
246-
} else if (this.preTouchTime) {
247-
preTime = this.preTouchTime;
248234
}
249235
if (Math.abs(preTime - this.focusTime) < 20) {
250236
return;
251237
}
252238
this.focusTime = 0;
253239
}
254240
this.preClickTime = 0;
255-
this.preTouchTime = 0;
256241
event.preventDefault();
257242
const nextVisible = !this.state.popupVisible;
258243
if (this.isClickToHide() && !nextVisible || nextVisible && this.isClickToShow()) {
@@ -377,11 +362,6 @@ const Trigger = React.createClass({
377362
this.clickOutsideHandler.remove();
378363
this.clickOutsideHandler = null;
379364
}
380-
381-
if (this.touchOutsideHandler) {
382-
this.touchOutsideHandler.remove();
383-
this.touchOutsideHandler = null;
384-
}
385365
},
386366

387367
createTwoChains(event) {
@@ -451,11 +431,9 @@ const Trigger = React.createClass({
451431
if (this.isClickToHide() || this.isClickToShow()) {
452432
newChildProps.onClick = this.onClick;
453433
newChildProps.onMouseDown = this.onMouseDown;
454-
newChildProps.onTouchStart = this.onTouchStart;
455434
} else {
456435
newChildProps.onClick = this.createTwoChains('onClick');
457436
newChildProps.onMouseDown = this.createTwoChains('onMouseDown');
458-
newChildProps.onTouchStart = this.createTwoChains('onTouchStart');
459437
}
460438
if (this.isMouseEnterToShow()) {
461439
newChildProps.onMouseEnter = this.onMouseEnter;

0 commit comments

Comments
 (0)