File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -46,6 +46,12 @@ Use the compact variant by setting `size` to `"compact"`.
4646
4747<FileSource src="/framed/TreeView/TreeViewCompact" />
4848
49+ ## With links
50+
51+ Add links to leaf nodes by defining an `href` property. Link nodes render as `<a>` elements with `role="treeitem"`. When a link node is active, `aria-current="page"` is used. Disabled link nodes omit the `href` attribute.
52+
53+ <FileSource src="/framed/TreeView/TreeViewLinks" />
54+
4955## With icons
5056
5157Add icons to nodes by defining an `icon` property with a Carbon Svelte icon component.
Original file line number Diff line number Diff line change 1+ <script >
2+ import { Stack , TreeView } from " carbon-components-svelte" ;
3+
4+ let activeId = " " ;
5+ let selectedIds = [];
6+ let nodes = [
7+ {
8+ id: 0 ,
9+ text: " IBM Cloud" ,
10+ href: " https://cloud.ibm.com" ,
11+ target: " _blank" ,
12+ },
13+ {
14+ id: 1 ,
15+ text: " Services" ,
16+ nodes: [
17+ {
18+ id: 2 ,
19+ text: " AI / Machine learning" ,
20+ href: " https://cloud.ibm.com/catalog#ai" ,
21+ target: " _blank" ,
22+ },
23+ {
24+ id: 3 ,
25+ text: " Analytics" ,
26+ href: " https://cloud.ibm.com/catalog#analytics" ,
27+ target: " _blank" ,
28+ },
29+ {
30+ id: 4 ,
31+ text: " Databases" ,
32+ href: " https://cloud.ibm.com/catalog#databases" ,
33+ target: " _blank" ,
34+ },
35+ ],
36+ },
37+ {
38+ id: 5 ,
39+ text: " Documentation" ,
40+ href: " https://cloud.ibm.com/docs" ,
41+ target: " _blank" ,
42+ },
43+ {
44+ id: 6 ,
45+ text: " Unavailable" ,
46+ href: " https://cloud.ibm.com/unavailable" ,
47+ disabled: true ,
48+ },
49+ ];
50+ </script >
51+
52+ <Stack gap ={6 }>
53+ <div >
54+ <TreeView
55+ labelText =" Cloud Resources"
56+ {nodes }
57+ bind:activeId
58+ bind:selectedIds
59+ on:select ={({ detail }) => console .log (" select" , detail )}
60+ />
61+ </div >
62+ <Stack gap ={4 }>
63+ <div >Active node id: {activeId }</div >
64+ <div >Selected ids: {JSON .stringify (selectedIds )}</div >
65+ </Stack >
66+ </Stack >
You can’t perform that action at this time.
0 commit comments