Programmatically expand/collapse TreeView nodes (#850)

* feat(tree-view): add accessors to programmatically expand/collapse nodes

* feat(tree-view): update docs/types

* test(tree-view): test updated TreeView accessors

* docs(tree-view): document TreeView accessors
This commit is contained in:
Eric Liu 2021-10-13 08:54:37 -07:00 committed by GitHub
commit c4413636a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 447 additions and 11 deletions

View file

@ -3,6 +3,7 @@
import type { TreeNodeId } from "../types/TreeView/TreeView";
import Analytics16 from "carbon-icons-svelte/lib/Analytics16";
let treeview: TreeView;
let activeId: TreeNodeId = "";
let selectedIds = [];
let expandedIds = [1];
@ -46,9 +47,21 @@
children: [{ id: 15, text: "IBM API Connect", disabled: true }],
},
];
$: if (treeview) {
treeview.expandAll();
treeview.expandNodes((node) => {
return node.id > 0;
});
treeview.collapseAll();
treeview.collapseNodes((node) => {
return node.disabled;
});
}
</script>
<TreeView
bind:this="{treeview}"
size="compact"
labelText="Cloud Products"
children="{children}"