From 6a4840a85c676ec8a78e6d86c43845d34e1d2c88 Mon Sep 17 00:00:00 2001 From: Yaoyao Lin Date: Tue, 29 Nov 2022 10:53:22 -0800 Subject: [PATCH] add new prop to configure tree node selectable --- components/tree/index.jsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/components/tree/index.jsx b/components/tree/index.jsx index d2883e3ee8..9aaf1d24ca 100644 --- a/components/tree/index.jsx +++ b/components/tree/index.jsx @@ -103,11 +103,16 @@ const propTypes = { * Styles to be added to the top-level `ul` element. Useful for `overflow:hidden`. */ listStyle: PropTypes.object, + /** + * Indicate whether a tree node is selectable + */ + treeNodeSelectable: PropTypes.boolean, }; const defaultProps = { assistiveText: {}, getNodes: (node) => node.nodes, + treeNodeSelectable: true, }; /* Flattens hierarchical tree structure into a flat array. The @@ -189,6 +194,9 @@ class Tree extends React.Component { } handleSelect = ({ event, data, clearSelectedNodes, fromFocus }) => { + if (!this.props.treeNodeSelectable) { + return; + } // When triggered by a key event, other nodes should be deselected. if (clearSelectedNodes) { // TODO: This bad design. This is state modfication. State should be changed via setState only.