Skip to content

Commit 4466109

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 the `deep` prop only collapses at the specific level passed, and when a user opens that depth, all children are fully open. 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 fd162d1 commit 4466109

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/components/Tree/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ export default defineComponent({
2020
type: Number,
2121
default: Infinity,
2222
},
23+
deepCollapseChildren: {
24+
type: Boolean,
25+
default: false,
26+
},
2327
// Data root path.
2428
path: {
2529
type: String,
@@ -57,9 +61,12 @@ export default defineComponent({
5761
translateY: 0,
5862
visibleData: null as FlatDataType | null,
5963
hiddenPaths: jsonFlatten(props.data, props.path).reduce((acc, item) => {
64+
const depthComparison = this.deepCollapseChildren
65+
? item.level >= this.deep
66+
: item.level === this.deep;
6067
if (
6168
(item.type === 'objectStart' || item.type === 'arrayStart') &&
62-
item.level === props.deep
69+
depthComparison
6370
) {
6471
return {
6572
...acc,

0 commit comments

Comments
 (0)