react-fastclick
Advanced tools
Comparing version
{ | ||
"name": "react-fastclick", | ||
"version": "3.0.1", | ||
"version": "3.0.2-alpha.1", | ||
"description": "Fast Touch Events for React", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -111,6 +111,14 @@ 'use strict'; | ||
var onMouseEvent = function (callback, event) { | ||
var touched = !noTouchHappened(); | ||
// Prevent mouse events on other elements | ||
if (touched && event.target !== touchEvents.target) { | ||
event.preventDefault(); | ||
} | ||
// Prevent any mouse events if we touched recently | ||
if (typeof callback === 'function' && noTouchHappened()) { | ||
if (typeof callback === 'function' && !touched) { | ||
callback(event); | ||
} | ||
if (event.type === 'click') { | ||
@@ -127,2 +135,3 @@ touchEvents.invalid = false; | ||
touchEvents.touched = true; | ||
touchEvents.target = event.target; | ||
touchEvents.lastTouchDate = new Date().getTime(); | ||
@@ -129,0 +138,0 @@ |
@@ -127,2 +127,77 @@ 'use strict'; | ||
it('should not prevent default on same target', function () { | ||
var event = { | ||
target: 'target', | ||
touches: [], | ||
preventDefault: spy() | ||
}; | ||
var props = { | ||
onTouchStart: spy(), | ||
onTouchMove: spy(), | ||
onTouchEnd: spy(), | ||
onMouseDown: spy(), | ||
onMouseMove: spy(), | ||
onMouseUp: spy(), | ||
onClick: spy() | ||
}; | ||
var node = renderIntoApp(fastclickCreateElement('div', props)); | ||
for (var key in props) { | ||
var eventType = handlerKeyToSimulatedEventKey(key); | ||
TestUtils.Simulate[eventType](node, event); | ||
if (eventType.indexOf('touch') >= 0) { | ||
expect(props[key]).to.have.been.calledOnce; | ||
} else { | ||
expect(props[key]).not.to.have.been.called; | ||
} | ||
} | ||
expect(event.preventDefault.callCount).to.equal(0); | ||
}); | ||
it('should prevent default on different target', function () { | ||
var event1 = { | ||
target: 'target1', | ||
touches: [], | ||
preventDefault: spy() | ||
}; | ||
var event2 = { | ||
target: 'target2', | ||
touches: [], | ||
preventDefault: spy() | ||
}; | ||
var props = { | ||
onTouchStart: spy(), | ||
onTouchMove: spy(), | ||
onTouchEnd: spy(), | ||
onMouseDown: spy(), | ||
onMouseMove: spy(), | ||
onMouseUp: spy(), | ||
onClick: spy() | ||
}; | ||
var node = renderIntoApp(fastclickCreateElement('div', props)); | ||
for (var key in props) { | ||
var eventType = handlerKeyToSimulatedEventKey(key); | ||
if (eventType.indexOf('touch') >= 0) { | ||
TestUtils.Simulate[eventType](node, event1); | ||
expect(props[key]).to.have.been.calledOnce; | ||
} else { | ||
TestUtils.Simulate[eventType](node, event2); | ||
expect(props[key]).not.to.have.been.called; | ||
} | ||
} | ||
expect(event1.preventDefault.callCount).to.equal(0); | ||
expect(event2.preventDefault.callCount).to.equal(4); | ||
}); | ||
}); | ||
@@ -129,0 +204,0 @@ |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
32673
7.23%870
8.34%1
Infinity%