Skip to content

Commit 0cdcfa8

Browse files
authored
Collapse children greater than or equal to depth
When a user specifies a depth to be collapsed, the intention is to make the JSON tidy so it is easy to visually parse. Currently when the user then expands an item, it expands all its children fully, which is rarely the intention. I think this should collapse all children beyond the depth level, so that when the items are opened up the children are collapsed. That said, for backwards compatibility I've implemented this as a new prop, defaulting to false, so that anyone upgrading won't see a change in behaviour.
1 parent cc2e0f2 commit 0cdcfa8

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/components/Tree/index.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ export default {
5555
type: Number,
5656
default: Infinity,
5757
},
58+
deepCollapseChildren: {
59+
type: Boolean,
60+
default: false,
61+
},
5862
// 数据层级顶级路径
5963
path: {
6064
type: String,
@@ -129,9 +133,12 @@ export default {
129133
translateY: 0,
130134
visibleData: null,
131135
hiddenPaths: jsonFlatten(this.data, this.path).reduce((acc, item) => {
136+
const depthComparison = this.deepCollapseChildren
137+
? item.level >= this.deep
138+
: item.level === this.deep;
132139
if (
133140
(item.type === 'objectStart' || item.type === 'arrayStart') &&
134-
item.level === this.deep
141+
depthComparison
135142
) {
136143
return {
137144
...acc,

0 commit comments

Comments
 (0)