From 58988820826c83561dbd299147b8f95f451206cd Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Fri, 27 Mar 2020 14:24:44 +0000 Subject: [PATCH] Fix collapsing panel --- src/app/ui/TreeView.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/app/ui/TreeView.js b/src/app/ui/TreeView.js index c1db3c1f92..fee5661b79 100644 --- a/src/app/ui/TreeView.js +++ b/src/app/ui/TreeView.js @@ -45,6 +45,7 @@ class TreeView { this.extractData = opts.extractData || this.extractDataDefault this.formatSelf = opts.formatSelf || this.formatSelfDefault this.view = null + this.expandPath = [] } render (json, expand) { @@ -86,14 +87,20 @@ class TreeView { ${caret} ${self.formatSelf(key, data, li)} ` + const expanded = self.expandPath.includes(keyPath) li.appendChild(label) if (data.children) { var list = yo`` - list.style.display = 'none' + list.style.display = expanded ? 'block' : 'none' caret.className = list.style.display === 'none' ? `fas fa-caret-right caret ${css.caret_tv}` : `fas fa-caret-down caret ${css.caret_tv}` caret.setAttribute('data-id', `treeViewToggle${keyPath}`) label.onclick = function () { self.expand(keyPath) + if (self.isExpanded(keyPath)) { + if (!self.expandPath.includes(keyPath)) self.expandPath.push(keyPath) + } else { + self.expandPath = self.expandPath.filter(path => path != keyPath) + } } label.oncontextmenu = function (event) { self.event.trigger('nodeRightClick', [keyPath, data, label, event])