Skip to content

Commit 62acc31

Browse files
authored
Merge pull request #2087 from AlexVvx/disable-drag-on-rightclick
Check if not a left-click, then bail out of onStart
2 parents f1faa28 + a33d1e7 commit 62acc31

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/components/dragelement/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ dragElement.init = function init(options) {
7878
element.ontouchstart = onStart;
7979

8080
function onStart(e) {
81+
if(e.buttons && e.buttons === 2) { // right click
82+
return;
83+
}
84+
8185
// make dragging and dragged into properties of gd
8286
// so that others can look at and modify them
8387
gd._dragged = false;

test/jasmine/tests/dragelement_test.js

+22-4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ describe('dragElement', function() {
3030

3131
afterEach(destroyGraphDiv);
3232

33+
function countCoverSlip() {
34+
return d3.selectAll('.dragcover').size();
35+
}
36+
3337
it('should init drag element', function() {
3438
var options = { element: this.element, gd: this.gd };
3539
dragElement.init(options);
@@ -103,10 +107,6 @@ describe('dragElement', function() {
103107
});
104108

105109
it('should add a cover slip div to the DOM', function() {
106-
function countCoverSlip() {
107-
return d3.selectAll('.dragcover').size();
108-
}
109-
110110
var options = { element: this.element, gd: this.gd };
111111
dragElement.init(options);
112112

@@ -122,6 +122,24 @@ describe('dragElement', function() {
122122
expect(countCoverSlip()).toEqual(0);
123123
});
124124

125+
it('should not add a cover slip div to the DOM when right click', function() {
126+
var options = { element: this.element, gd: this.gd };
127+
dragElement.init(options);
128+
129+
var mockObj = {
130+
handleClick: function() {}
131+
};
132+
spyOn(mockObj, 'handleClick');
133+
134+
this.element.onclick = mockObj.handleClick;
135+
136+
mouseEvent('mousedown', this.x, this.y, { buttons: 2 });
137+
expect(countCoverSlip()).toEqual(0);
138+
139+
mouseEvent('mouseup', this.x, this.y);
140+
expect(mockObj.handleClick).not.toHaveBeenCalled();
141+
});
142+
125143
it('should fire off click event when down/up without dragging', function() {
126144
var options = { element: this.element, gd: this.gd };
127145
dragElement.init(options);

0 commit comments

Comments
 (0)