From fcd21db9b546bfc08e7b2e8d77dd0704ed2d738e Mon Sep 17 00:00:00 2001 From: Kamil Zachradnik <41974949+Kamilos1337@users.noreply.github.com> Date: Mon, 4 Nov 2024 16:23:28 +0100 Subject: [PATCH] Checks if collapsed value is defined by user, if not its false as it was --- src/Tree/index.tsx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Tree/index.tsx b/src/Tree/index.tsx index cc36898a..73ff9eb2 100644 --- a/src/Tree/index.tsx +++ b/src/Tree/index.tsx @@ -210,12 +210,14 @@ class Tree extends React.Component { const d = Array.isArray(data) ? data : [data]; return d.map(n => { const nodeDatum = n as TreeNodeDatum; - nodeDatum.__rd3t = { id: null, depth: null, collapsed: false }; - nodeDatum.__rd3t.id = uuidv4(); - // D3@v5 compat: manually assign `depth` to node.data so we don't have - // to hold full node+link sets in state. - // TODO: avoid this extra step by checking D3's node.depth directly. - nodeDatum.__rd3t.depth = currentDepth; + nodeDatum.__rd3t = { + id: uuidv4(), + depth: currentDepth || null, + collapsed: nodeDatum.__rd3t && typeof nodeDatum.__rd3t.collapsed === 'boolean' + ? nodeDatum.__rd3t.collapsed + : false, + }; + // If there are children, recursively assign properties to them too. if (nodeDatum.children && nodeDatum.children.length > 0) { nodeDatum.children = Tree.assignInternalProperties(nodeDatum.children, currentDepth + 1);