Skip to content

Commit e473c68

Browse files
committed
docs(tree-view): add "With links" example
1 parent 8ee8f5d commit e473c68

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

docs/src/pages/components/TreeView.svx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff 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

5157
Add icons to nodes by defining an `icon` property with a Carbon Svelte icon component.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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>

0 commit comments

Comments
 (0)