Skip to content

Commit 661c587

Browse files
authored
Fix/right clicks (#140)
* Fix right click callbacks * Add sample right clicks integration
1 parent b7090dd commit 661c587

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
lines changed

sandbox/Sandbox.jsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,18 @@ export default class Sandbox extends React.Component {
5555

5656
onClickNode = id => !this.state.config.collapsible && window.alert(`Clicked node ${id}`);
5757

58+
onRightClickNode = (event, id) => {
59+
event.preventDefault();
60+
window.alert(`RIGHT clicked node ${id}`);
61+
};
62+
5863
onClickLink = (source, target) => window.alert(`Clicked link between ${source} and ${target}`);
5964

65+
onRightClickLink = (event, source, target) => {
66+
event.preventDefault();
67+
window.alert(`RIGHT clicked link between ${source} and ${target}`);
68+
};
69+
6070
onMouseOverNode = id => console.info(`Do something when mouse is over node (${id})`);
6171

6272
onMouseOutNode = id => console.info(`Do something when mouse is out of node (${id})`);
@@ -297,8 +307,10 @@ export default class Sandbox extends React.Component {
297307
data,
298308
config: this.state.config,
299309
onClickNode: this.onClickNode,
310+
onRightClickNode: this.onRightClickNode,
300311
onClickGraph: this.onClickGraph,
301312
onClickLink: this.onClickLink,
313+
onRightClickLink: this.onRightClickLink,
302314
onMouseOverNode: this.onMouseOverNode,
303315
onMouseOutNode: this.onMouseOutNode,
304316
onMouseOverLink: this.onMouseOverLink,

src/components/graph/Graph.jsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -407,16 +407,6 @@ export default class Graph extends React.Component {
407407
}
408408
};
409409

410-
/**
411-
* Calls the callback passed to the component.
412-
* @param {Object} event - the event object generated by the event.
413-
* @param {string} clickedNodeId - The id of the node where the click was performed.
414-
* @returns {undefined}
415-
*/
416-
onRightClickNode = (event, clickedNodeId) => {
417-
this.props.onRightClickNode && this.props.onRightClickNode(event, clickedNodeId);
418-
};
419-
420410
/**
421411
* Calls the callback passed to the component.
422412
* @param {Object} e - The event of onClick handler.
@@ -439,15 +429,15 @@ export default class Graph extends React.Component {
439429
this.state.nodes,
440430
{
441431
onClickNode: this.onClickNode,
442-
onRightClickNode: this.onRightClickNode,
432+
onRightClickNode: this.props.onRightClickNode,
443433
onMouseOverNode: this.onMouseOverNode,
444434
onMouseOut: this.onMouseOutNode
445435
},
446436
this.state.d3Links,
447437
this.state.links,
448438
{
449439
onClickLink: this.props.onClickLink,
450-
onRightClickLink: this.onRightClickLink,
440+
onRightClickLink: this.props.onRightClickLink,
451441
onMouseOverLink: this.onMouseOverLink,
452442
onMouseOutLink: this.onMouseOutLink
453443
},

src/components/link/Link.jsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import React from 'react';
77
* window.alert(`Clicked link between ${source} and ${target}`);
88
* };
99
*
10-
* const onRightClickLink = function(event, source, target) {
10+
* const onRightClickLink = function(source, target) {
1111
* window.alert(`Right clicked link between ${source} and ${target}`);
1212
* };
1313
*
@@ -43,12 +43,11 @@ export default class Link extends React.Component {
4343

4444
/**
4545
* Handle link right click event.
46-
* @param {Object} event - the event object
46+
* @param {Object} event - native event.
4747
* @returns {undefined}
4848
*/
49-
handleOnRightClickLink = event => {
49+
handleOnRightClickLink = event =>
5050
this.props.onRightClickLink && this.props.onRightClickLink(event, this.props.source, this.props.target);
51-
};
5251

5352
/**
5453
* Handle mouse over link event.

src/components/node/Node.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import nodeHelper from './node.helper';
1111
* window.alert('Clicked node', nodeId);
1212
* };
1313
*
14-
* const onRightClickNode = function(event, nodeId) {
14+
* const onRightClickNode = function(nodeId) {
1515
* window.alert('Right clicked node', nodeId);
1616
* }
1717
*
@@ -56,10 +56,10 @@ export default class Node extends React.Component {
5656

5757
/**
5858
* Handle right click on the node.
59-
* @param {Object} event - the event object
59+
* @param {Object} event - native event.
6060
* @returns {undefined}
6161
*/
62-
handleOnRightClickNode = event => this.props.onRightClickNode && this.props.onClickNode(event, this.props.id);
62+
handleOnRightClickNode = event => this.props.onRightClickNode && this.props.onRightClickNode(event, this.props.id);
6363

6464
/**
6565
* Handle mouse over node event.

0 commit comments

Comments
 (0)