Navigation
Tree
A hierarchical list for file systems, navigation, and any parent-child data. Compose nana-tree-item nodes inside it. Implements the ARIA tree pattern: roving tabindex, arrow-key navigation, type-ahead, and Home/End/* support.
Preview
Section titled “Preview”<nana-tree style="width: 100%">
<nana-tree-item>
Parent
<nana-tree-item>Child one</nana-tree-item>
<nana-tree-item>Child two</nana-tree-item>
</nana-tree-item>
</nana-tree> - Riverside Court
- Block A
- Unit 4B
- Unit 5C
- Block B
- Hilltop Gardens
- Archived
<script lang="ts">
import { NanaTree } from '$lib/components/ui/tree';
let selected = $state<string[]>(['a-4b']);
let expanded = $state<string[]>(['riverside', 'block-a']);
const items = [
{
id: 'riverside',
label: 'Riverside Court',
children: [
{
id: 'block-a',
label: 'Block A',
children: [
{ id: 'a-4b', label: 'Unit 4B' },
{ id: 'a-5c', label: 'Unit 5C' },
],
},
{ id: 'block-b', label: 'Block B', children: [{ id: 'b-1a', label: 'Unit 1A' }] },
],
},
{ id: 'hilltop', label: 'Hilltop Gardens', children: [{ id: 'h-2', label: 'Unit 2' }] },
{ id: 'archive', label: 'Archived', disabled: true },
];
</script>
<div class="w-full max-w-xs">
<NanaTree label="Properties" {items} bind:selected bind:expanded />
</div> Installation
Section titled “Installation”Install the package for a versioned dependency:
npm install @nana-tec/ui-componentsOr copy the source in and own it:
npx @nana-tec/ui add tree --framework web-componentsnpx @nana-tec/ui add tree --framework svelteLands in src/lib/components/ui/tree/ as NanaTree.svelte, styled with Tailwind
classes that resolve to the design tokens. Requires Tailwind v4.
Import
Section titled “Import”
Import the autoloader once, in your app's entry point. Every <nana-*> tag then works anywhere, and
each component downloads only the first time a page uses it:
import "@nana-tec/ui-components/autoloader";import "@nana-tec/ui-components/theme";The second line gives every component the Nana look and the design tokens behind it. Leave it out to style the components entirely yourself.
Import a component directly when it must be ready at once: on screen at first paint, or when you call its methods straight away. The two mix freely:
import "@nana-tec/ui-components/tree";
Copied in with npx @nana-tec/ui add tree? Import your project's own
@/lib/nana-ui/autoloader.js once instead; the CLI keeps it up to date.
<script lang="ts"> import { NanaTree } from '$lib/components/ui/tree';
let selected = $state<string[]>([]);</script>
<NanaTree label="Properties" {items} bind:selected selection="single" />Arrow keys walk the visible items; Right opens a branch and Left closes it or moves to
the parent; * opens every sibling; typing jumps to a match. selection is single,
multiple or none. The icon snippet receives each item and whether it is open.
Basic usage
Section titled “Basic usage”<nana-tree style="width:100%"> <nana-tree-item> Parent <nana-tree-item>Child one</nana-tree-item> <nana-tree-item>Child two</nana-tree-item> </nana-tree-item></nana-tree>Properties
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
label | label | string | '' | Accessible name for the tree. |
selection | selection | TreeSelection | 'single' | Selection behaviour. |
size | size | TreeSize | 'default' | Density scale. |
Events
| Event | Description |
|---|---|
nana-selection-change | Selection changed (detail.selection). |
nana-expand | A branch expanded (detail.item). |
nana-collapse | A branch collapsed (detail.item). |
Slots
| Slot | Description |
|---|---|
(default) | The top-level nana-tree-item nodes. |
CSS parts
| Part | Description |
|---|---|
::part(base) | The tree container. |
CSS custom properties
| Property | Description |
|---|---|
--nana-tree-indent | Indent step per depth level. |
--nana-tree-row-height | Node row height. |
--nana-tree-connector | Connector line colour. |
NanaTree
| Prop | Type | Default |
|---|---|---|
itemsrequired | readonly TreeItem[] | |
expandedbind: | string[] | [] |
selectedbind: | string[] | [] |
selection | TreeSelection | 'single' |
label | string | |
icon | Snippet<[TreeItem, boolean]> | |
onSelectedChange | (selected: string[]) => void | |
onExpandedChange | (expanded: string[]) => void |
Also accepts Omit<HTMLAttributes<HTMLUListElement>, 'class'>.