On this Page
TreeItem
TreeItem describes one node in the data passed to TreeView. It is a recursive TypeScript interface, not a rendered component.
Usage
Svelte
<script lang="ts">
import { TreeView, type TreeItem } from 'fractalsvelte';
const items: TreeItem[] = [
{
id: 'src',
label: 'src',
children: [
{ id: 'routes', label: 'routes' },
{ id: 'lib', label: 'lib', disabled: true }
]
}
];
</script>
<TreeView {items} />
Use unique, stable id values. Nested children use the same TreeItem shape, allowing any depth of hierarchy.
API
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Stable identifier used for selection, expansion, and reordering. |
label | string | Yes | Visible text for the node. |
disabled | boolean | No | When true, prevents the node from being selected or interacted with. |
children | TreeItem[] | No | Child nodes rendered beneath this item. |
TreeView accepts TreeItem[] through its required items prop. Its selection and expansion callbacks return the relevant item ids, while reorder mode returns a new TreeItem[] hierarchy.
Related
Use TreeView to render the hierarchy. For immutable tree rearrangement outside the component, use TreeNode and moveTreeNode from fractalsvelte/motion.
