From 153dba4f9d59f3d8aab49606f657ddae5e4e6c74 Mon Sep 17 00:00:00 2001 From: Matthias Herzkamp Date: Wed, 5 May 2021 14:00:51 +0200 Subject: [PATCH] feature/#270: expose event that caused a change to setChecked, setExpanded, onClick and other user functions --- src/js/CheckboxTree.js | 23 ++++++++++++----------- src/js/TreeNode.js | 14 +++++++------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/js/CheckboxTree.js b/src/js/CheckboxTree.js index d0b3d542..a51d0ad9 100644 --- a/src/js/CheckboxTree.js +++ b/src/js/CheckboxTree.js @@ -133,47 +133,48 @@ class CheckboxTree extends React.Component { return newState; } - onCheck(nodeInfo) { + onCheck(nodeInfo, event) { const { checkModel, noCascade, onCheck } = this.props; const model = this.state.model.clone(); const node = model.getNode(nodeInfo.value); model.toggleChecked(nodeInfo, nodeInfo.checked, checkModel, noCascade); - onCheck(model.serializeList('checked'), { ...node, ...nodeInfo }); + onCheck(model.serializeList('checked'), { ...node, ...nodeInfo }, event); } - onExpand(nodeInfo) { + onExpand(nodeInfo, event) { const { onExpand } = this.props; const model = this.state.model.clone(); const node = model.getNode(nodeInfo.value); model.toggleNode(nodeInfo.value, 'expanded', nodeInfo.expanded); - onExpand(model.serializeList('expanded'), { ...node, ...nodeInfo }); + onExpand(model.serializeList('expanded'), { ...node, ...nodeInfo }, event); } - onNodeClick(nodeInfo) { + onNodeClick(nodeInfo, event) { const { onClick } = this.props; const { model } = this.state; const node = model.getNode(nodeInfo.value); - onClick({ ...node, ...nodeInfo }); + onClick({ ...node, ...nodeInfo }, event); } - onExpandAll() { - this.expandAllNodes(); + onExpandAll(event) { + this.expandAllNodes(event); } - onCollapseAll() { - this.expandAllNodes(false); + onCollapseAll(event) { + this.expandAllNodes(false, event); } - expandAllNodes(expand = true) { + expandAllNodes(expand = true, event) { const { onExpand } = this.props; onExpand( this.state.model.clone() .expandAllNodes(expand) .serializeList('expanded'), + event, ); } diff --git a/src/js/TreeNode.js b/src/js/TreeNode.js index 3b4f7307..fc2267d3 100644 --- a/src/js/TreeNode.js +++ b/src/js/TreeNode.js @@ -55,13 +55,13 @@ class TreeNode extends React.PureComponent { this.onExpand = this.onExpand.bind(this); } - onCheck() { + onCheck(event) { const { value, onCheck } = this.props; - onCheck({ value, checked: this.getCheckState({ toggle: true }) }); + onCheck({ value, checked: this.getCheckState({ toggle: true }) }, event); } - onClick() { + onClick(event) { const { expandOnClick, isParent, @@ -71,16 +71,16 @@ class TreeNode extends React.PureComponent { // Auto expand if enabled if (isParent && expandOnClick) { - this.onExpand(); + this.onExpand(event); } - onClick({ value, checked: this.getCheckState({ toggle: false }) }); + onClick({ value, checked: this.getCheckState({ toggle: false }) }, event); } - onExpand() { + onExpand(event) { const { expanded, value, onExpand } = this.props; - onExpand({ value, expanded: !expanded }); + onExpand({ value, expanded: !expanded }, event); } getCheckState({ toggle }) {