Skip to content

Commit 7c6b2fb

Browse files
committed
add onClick
1 parent 3a70800 commit 7c6b2fb

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/org_tree.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ export const renderBtn = (data, prop ) => {
4343

4444
return React.createElement('span', {
4545
className: cls.join(' '),
46-
onClick: (e) => typeof onExpand === 'function' && onExpand(e, data)
46+
onClick: (e) => {
47+
e.stopPropagation();
48+
typeof onExpand === 'function' && onExpand(e, data);
49+
}
4750
});
4851
};
4952

@@ -52,6 +55,7 @@ export const renderLabel = (data, prop) => {
5255
const node = prop.node;
5356
const label = data[node.label];
5457
const renderContent = prop.renderContent;
58+
const onClick = prop.onClick;
5559

5660
const childNodes = [];
5761
if (typeof renderContent === 'function') {
@@ -78,9 +82,10 @@ export const renderLabel = (data, prop) => {
7882

7983
return React.createElement('div', {
8084
className: 'org-tree-node-label',
85+
onClick: (e) => typeof onClick === 'function' && onClick(e, data)
8186
}, [React.createElement('div', {
8287
className: cls.join(' '),
83-
style: { width: labelWidth },
88+
style: { width: labelWidth }
8489
}, childNodes)]);
8590
};
8691

src/org_tree.jsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class OrgTree extends Component {
6363
}
6464

6565
render() {
66-
const { horizontal, node, data } = this.props;
66+
const { horizontal, node, data, onClick } = this.props;
6767
return <div className="org-tree-container">
6868
<div className={classnames('org-tree', {
6969
'horizontal': horizontal
@@ -72,6 +72,7 @@ class OrgTree extends Component {
7272
data={data}
7373
node={node}
7474
onExpand={(e, nodeData)=> this.handleExpand(e, nodeData)}
75+
onClick={(e, nodeData)=> onClick && onClick(e, nodeData)}
7576
{...this.props}
7677
/>
7778
</div>
@@ -87,7 +88,8 @@ OrgTree.propTypes = {
8788
expandAll: PropTypes.bool,
8889
renderContent: PropTypes.func,
8990
labelWidth: PropTypes.number,
90-
labelClassName: PropTypes.string
91+
labelClassName: PropTypes.string,
92+
onClick: PropTypes.func
9193
}
9294

9395
OrgTree.defaultProps = {

0 commit comments

Comments
 (0)