Skip to content

Commit

Permalink
add onClick
Browse files Browse the repository at this point in the history
  • Loading branch information
artdong committed Apr 1, 2020
1 parent 3a70800 commit 7c6b2fb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/org_tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ export const renderBtn = (data, prop ) => {

return React.createElement('span', {
className: cls.join(' '),
onClick: (e) => typeof onExpand === 'function' && onExpand(e, data)
onClick: (e) => {
e.stopPropagation();
typeof onExpand === 'function' && onExpand(e, data);
}
});
};

Expand All @@ -52,6 +55,7 @@ export const renderLabel = (data, prop) => {
const node = prop.node;
const label = data[node.label];
const renderContent = prop.renderContent;
const onClick = prop.onClick;

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

return React.createElement('div', {
className: 'org-tree-node-label',
onClick: (e) => typeof onClick === 'function' && onClick(e, data)
}, [React.createElement('div', {
className: cls.join(' '),
style: { width: labelWidth },
style: { width: labelWidth }
}, childNodes)]);
};

Expand Down
6 changes: 4 additions & 2 deletions src/org_tree.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class OrgTree extends Component {
}

render() {
const { horizontal, node, data } = this.props;
const { horizontal, node, data, onClick } = this.props;
return <div className="org-tree-container">
<div className={classnames('org-tree', {
'horizontal': horizontal
Expand All @@ -72,6 +72,7 @@ class OrgTree extends Component {
data={data}
node={node}
onExpand={(e, nodeData)=> this.handleExpand(e, nodeData)}
onClick={(e, nodeData)=> onClick && onClick(e, nodeData)}
{...this.props}
/>
</div>
Expand All @@ -87,7 +88,8 @@ OrgTree.propTypes = {
expandAll: PropTypes.bool,
renderContent: PropTypes.func,
labelWidth: PropTypes.number,
labelClassName: PropTypes.string
labelClassName: PropTypes.string,
onClick: PropTypes.func
}

OrgTree.defaultProps = {
Expand Down

0 comments on commit 7c6b2fb

Please sign in to comment.