Skip to content

Check if not a left-click, then bail out of onStart #2087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 16, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/components/dragelement/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ dragElement.init = function init(options) {
element.ontouchstart = onStart;

function onStart(e) {
if(e.button && e.button === 2) { // right click
return;
}

// make dragging and dragged into properties of gd
// so that others can look at and modify them
gd._dragged = false;
Expand Down
13 changes: 13 additions & 0 deletions test/jasmine/tests/dragelement_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,19 @@ describe('dragElement', function() {
expect(countCoverSlip()).toEqual(0);
});

it('should not add a cover slip div to the DOM when right click', function() {
function countCoverSlip() {
return d3.selectAll('.dragcover').size();
}

var options = { element: this.element, gd: this.gd };
dragElement.init(options);

options.element.onmousedown({button: 2})
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, that it's a best way to emulate right click, however I can't see any other options.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like in mouse_event we have buttons but if we add button the same way it should allow right-click simulation?


expect(countCoverSlip()).toEqual(0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Very clear correspondence to the test above. Two last changes I would suggest, then I think this is ready to go:

  • 🌴 Can you move countCoverSlip out one scope so we don't have to repeat it?
  • Can you continue through mouseup as in the test below, and verify that handleClick has not been called? (that one ironically looks annoying to DRY 🌴 so you can just repeat the pieces you need.)

Copy link
Author

@AlexVvx AlexVvx Oct 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, thank you

});

it('should fire off click event when down/up without dragging', function() {
var options = { element: this.element, gd: this.gd };
dragElement.init(options);
Expand Down