From 0231569d130b70aca38faef9dfeb41e7afdf2e45 Mon Sep 17 00:00:00 2001 From: Wugaoliang Date: Mon, 28 Jun 2021 21:04:58 +0800 Subject: [PATCH 1/4] fix: #1812 --- components/tree/Tree.js | 2 +- components/tree/customTreeNode.jsx | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/components/tree/Tree.js b/components/tree/Tree.js index 425abff14..0381c1c7c 100644 --- a/components/tree/Tree.js +++ b/components/tree/Tree.js @@ -396,7 +396,7 @@ const Tree = (props) => { m.onClick(node) } else { if (m.type === 'editNode') { - editNode(node) + editNode(node, e) } if (m.type === 'addSiblingNode') { addSiblingNode(node) diff --git a/components/tree/customTreeNode.jsx b/components/tree/customTreeNode.jsx index 4034ac8c4..5c50eda12 100644 --- a/components/tree/customTreeNode.jsx +++ b/components/tree/customTreeNode.jsx @@ -105,6 +105,7 @@ const CustomTreeNode = ({ onContextMenu={(e) => { if (editable && !node.disabled) { e.preventDefault() + console.log('e', e, ref) setMenuVisible(node.id) } }} From 66ab9ac1321492e7d2c1ec39cbf026d105e365bc Mon Sep 17 00:00:00 2001 From: wugaoliang Date: Tue, 29 Jun 2021 09:00:50 +0800 Subject: [PATCH 2/4] fix: #1812 --- components/tree/Tree.js | 12 +++++++++--- components/tree/customTreeNode.jsx | 1 - docs/demo/tree/section-edit.jsx | 12 ++++++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/components/tree/Tree.js b/components/tree/Tree.js index 0381c1c7c..28a47a63d 100644 --- a/components/tree/Tree.js +++ b/components/tree/Tree.js @@ -1,4 +1,4 @@ -import React, { useState, useCallback, useEffect } from 'react' +import React, { useState, useCallback, useEffect, useRef } from 'react' import BaseTree from './BaseTree' import Input from '../input' import Button from '../button' @@ -76,7 +76,7 @@ const Tree = (props) => { useEffect(() => { updateCacheData(data) }, [data]) - + const contextMenuFun = useRef() const [menuVisible, setMenuVisible] = useState(null) const [modalVisible, setModalVisible] = useState(null) @@ -333,6 +333,8 @@ const Tree = (props) => { if (result === true) { updateCacheData(dataCache) onSave(nodeEdited, dataCache) + } else { + cancelAddNode(enode) } } else { updateCacheData(dataCache) @@ -372,6 +374,9 @@ const Tree = (props) => { }, [cacheData, _deleteNode] ) + useEffect(() => { + contextMenuFun.current = { editNode, addChildNode, addSiblingNode, deleteNode } + }, [editNode, addChildNode, addSiblingNode, deleteNode]) const menuRender = useCallback( (node) => { @@ -384,6 +389,7 @@ const Tree = (props) => { if (contextMenu) { menu = contextMenu(node) } + return (