Skip to content

Commit 050135f

Browse files
authored
Merge pull request aframevr#4000 from dmarcos/emitClick
Always emit cursor click events if mouse based cursor enabled
2 parents 0a9e312 + 30e1554 commit 050135f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

‎src/components/cursor.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ module.exports.Component = registerComponent('cursor', {
242242
* in case user mousedowned one entity, dragged to another, and mouseupped.
243243
*/
244244
onCursorUp: function (evt) {
245+
var data = this.data;
245246
this.twoWayEmit(EVENTS.MOUSEUP);
246247

247248
// If intersected entity has changed since the cursorDown, still emit mouseUp on the
@@ -251,7 +252,8 @@ module.exports.Component = registerComponent('cursor', {
251252
this.cursorDownEl.emit(EVENTS.MOUSEUP, this.intersectedEventDetail);
252253
}
253254

254-
if (!this.data.fuse && this.intersectedEl && this.cursorDownEl === this.intersectedEl) {
255+
if ((!data.fuse || data.rayOrigin === 'mouse') &&
256+
this.intersectedEl && this.cursorDownEl === this.intersectedEl) {
255257
this.twoWayEmit(EVENTS.CLICK);
256258
}
257259

‎tests/components/cursor.test.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,16 @@ suite('cursor', function () {
155155
});
156156
component.onCursorUp();
157157
});
158+
159+
test('emits click event on intersectedEl when fuse and mouse cursor enabled', function (done) {
160+
el.setAttribute('cursor', 'fuse', true);
161+
el.setAttribute('cursor', 'rayOrigin', 'mouse');
162+
component.intersection = intersection;
163+
component.intersectedEl = intersectedEl;
164+
component.cursorDownEl = intersectedEl;
165+
once(intersectedEl, 'click', function () { done(); });
166+
component.onCursorUp({type: 'touchend', preventDefault: function () {}});
167+
});
158168
});
159169

160170
suite('onIntersection', function () {

0 commit comments

Comments
 (0)