From 00ce637fe4105dc058ad8e95f3cfd985db1c0833 Mon Sep 17 00:00:00 2001 From: woobottle Date: Mon, 1 Mar 2021 15:06:31 +0900 Subject: [PATCH] make sidebar child elements collapsed as default --- src/components/sidebar/tree.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/components/sidebar/tree.js b/src/components/sidebar/tree.js index bd3d23ae..4a808a1c 100644 --- a/src/components/sidebar/tree.js +++ b/src/components/sidebar/tree.js @@ -125,10 +125,15 @@ const Tree = ({ edges }) => { treeData.items.forEach(item => { if (config.sidebar.collapsedNav && config.sidebar.collapsedNav.includes(item.url)) { defaultCollapsed[item.url] = true; + if (item.items.length !== 0) { // Assume page has children that should be collapsed + item.items.forEach(child => { + defaultCollapsed[child.url] = true; + })} } else { defaultCollapsed[item.url] = false; } }); + const [collapsed, setCollapsed] = useState(defaultCollapsed); const toggle = url => {