Skip to content

Commit

Permalink
Merge pull request #19 from uxcore/fix-action-eventv2
Browse files Browse the repository at this point in the history
default actions ICON changed to more-dot
  • Loading branch information
lecepin committed Jan 18, 2019
2 parents 442bc47 + e38b00d commit 8d45f2b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

---

## 0.4.5

* `FIXED` for ActionTreeNode, fix the event stop propagation problem under react@15 and smaller
* `CHANGED` default actions ICON changed to more-dot

## 0.4.4

* `CHANGED` for ActionTreeNode, prevent click event to propagation on action item so it won't trigger selectable event on tree node
Expand Down
7 changes: 6 additions & 1 deletion demo/TreeDemo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,19 @@ class Demo extends React.Component {
selectable
expandedKeys={this.state.expandedKeys}
onExpand={this.onExpand}
autoExpandParent={this.state.autoExpandParent}
autoExpandParent
onDragStart={this.onDragStart}
onDragEnter={this.onDragEnter}
onDrop={this.onDrop}
onSelect={() => { console.log('onSelect 回调'); }}
>
{loopDropDown(gDropDownData)}
</Tree>
<button onClick={() => {
this.setState({
expandedKeys: ['0-0-1-1-key'],
});
}}>手动展开</button>
<h2>
dragable
</h2>
Expand Down
26 changes: 22 additions & 4 deletions src/ActionTreeNode.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import Menu from 'uxcore-menu';
const LOAD_STATUS_LOADING = 1;

class ActionTreeNode extends RcTree.TreeNode {
actionClickBlocker = false;

// Icon + Title
renderSelector = () => {
const { loadStatus, dragNodeHighlight } = this.state;
Expand Down Expand Up @@ -54,11 +56,24 @@ class ActionTreeNode extends RcTree.TreeNode {
)}
draggable={(!disabled && draggable) || undefined}
aria-grabbed={(!disabled && draggable) || undefined}

onMouseEnter={this.onMouseEnter}
onMouseLeave={this.onMouseLeave}
onContextMenu={this.onContextMenu}
onClick={this.onSelectorClick}
onClick={(e) => {
// the event stop propagation will fial in popover under react@15 or smaller, so try to
// block it by logic code
if (e.target && e.target.closest) {
this.actionClickBlocker = false;
if (e.target.closest('.uxcore-tree-node-actions-blocker')) {
return;
}
} else if (this.actionClickBlocker) {
this.actionClickBlocker = false;
return;
}

this.onSelectorClick(e);
}}
onDragStart={this.onDragStart}
>
{$icon}{$title}
Expand All @@ -81,10 +96,12 @@ class ActionTreeNode extends RcTree.TreeNode {
menuContent.push(<Menu.Item key={`${index + 1}`}>
<div onClick={(e) => {
e.stopPropagation();
this.actionClickBlocker = true;

value.onClick(value, index, e);
}}
>
{value.icon ? <Icon usei name={value.icon} /> : null}
{value.icon ? <Icon usei name={value.icon} className="kuma-tree-icon-valign" /> : null}
{value.text}
</div>
</Menu.Item>);
Expand All @@ -93,6 +110,7 @@ class ActionTreeNode extends RcTree.TreeNode {
renderActionContent = (<Dropdown
overlayClassName={classNames(
`${prefixCls}-dropdown-menu`,
'uxcore-tree-node-actions-blocker',
)}
overlay={<Menu>{menuContent}</Menu>}
getPopupContainer={node => node.parentNode}
Expand Down Expand Up @@ -155,7 +173,7 @@ ActionTreeNode.propTypes = {
ActionTreeNode.defaultProps = {
...RcTree.TreeNode.defaultProps,
actionAble: false,
actionIcon: 'shezhi',
actionIcon: 'more-dot',
actions: {
text: '',
onClick: () => {},
Expand Down
7 changes: 6 additions & 1 deletion src/Tree.less
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,9 @@
}
}
}


.kuma-tree-icon-valign {
vertical-align: -2px;
margin-right: 3px;
}

0 comments on commit 8d45f2b

Please sign in to comment.