Skip to content
Nana UI

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.

View .md Download
Parent Child one Child two

Install the package for a versioned dependency:

npm install @nana-tec/ui-components

Or copy the source in and own it:

npx @nana-tec/ui add tree --framework web-components
npx @nana-tec/ui add tree --framework svelte

Lands in src/lib/components/ui/tree/ as NanaTree.svelte, styled with Tailwind classes that resolve to the design tokens. Requires Tailwind v4.

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.

<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

PropertyAttributeTypeDefaultDescription
labellabelstring''Accessible name for the tree.
selectionselectionTreeSelection'single'Selection behaviour.
sizesizeTreeSize'default'Density scale.

Events

EventDescription
nana-selection-changeSelection changed (detail.selection).
nana-expandA branch expanded (detail.item).
nana-collapseA branch collapsed (detail.item).

Slots

SlotDescription
(default)The top-level nana-tree-item nodes.

CSS parts

PartDescription
::part(base)The tree container.

CSS custom properties

PropertyDescription
--nana-tree-indentIndent step per depth level.
--nana-tree-row-heightNode row height.
--nana-tree-connectorConnector line colour.

NanaTree

PropTypeDefault
itemsrequiredreadonly TreeItem[]
expandedbind:string[][]
selectedbind:string[][]
selectionTreeSelection'single'
labelstring
iconSnippet<[TreeItem, boolean]>
onSelectedChange(selected: string[]) => void
onExpandedChange(expanded: string[]) => void

Also accepts Omit<HTMLAttributes<HTMLUListElement>, 'class'>.