Navigation
Tree Item
A single node in a nana-tree. Branch nodes nest further nana-tree-item elements in the default slot; leaf nodes have none. The label comes from the label attribute (or the label slot for rich content).
Svelte has no item component: NanaTree takes its nodes as an items array. See Tree.
Preview
Section titled “Preview”<nana-tree style="width: 100%">
<nana-tree-item label="Parent" icon="folder" expanded>
<nana-tree-item label="Child one" icon="code-bracket"></nana-tree-item>
<nana-tree-item
label="Child two"
icon="code-bracket"
selected
></nana-tree-item>
</nana-tree-item>
</nana-tree> Installation
Section titled “Installation”npm install @nana-tec/ui-componentsImport
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-item";
Copied in with npx @nana-tec/ui add tree-item? Import your project's own
@/lib/nana-ui/autoloader.js once instead; the CLI keeps it up to date.
Basic usage
Section titled “Basic usage”<nana-tree style="width:100%"> <nana-tree-item label="Parent" icon="folder" expanded> <nana-tree-item label="Child" icon="code-bracket"></nana-tree-item> </nana-tree-item></nana-tree>Properties
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
badge | badge | string | undefined | — | Trailing badge text. |
disabled | disabled | boolean | false | Disabled — blocks selection, expansion, and keyboard interaction. |
expanded | expanded | boolean | false | Expanded state of a branch node. |
icon | icon | string | undefined | — | Leading icon name (a nana-icon name). |
label | label | string | '' | Plain-text label. Ignored when the label slot is used. |
lazy | lazy | boolean | false | Treat as a branch whose children load on first expand. |
loading | loading | boolean | false | Show a loading spinner in place of the chevron. |
selected | selected | boolean | false | Selected state (the tree controls this). |
Methods
| Method | Description |
|---|---|
collapse(): void | Collapse a branch. |
expand(): void | Expand a branch, requesting a lazy load on first open. |
toggle(): void | Expand the node if it is collapsed, collapse it if it is expanded |
Events
| Event | Description |
|---|---|
nana-tree-item-activate | Internal: row activated (handled by the tree). |
nana-tree-item-toggle | Internal: expanded state changed (handled by the tree). |
Slots
| Slot | Description |
|---|---|
(default) | Child nana-tree-item nodes. |
label | Rich label content (overrides the label attribute). |
CSS parts
| Part | Description |
|---|---|
::part(item) | The node row. |
::part(chevron) | The expand/collapse chevron. |
::part(toggle) | The control that expands and collapses the item; carries leaf, open |
::part(icon) | The leading icon. |
::part(label) | The label. |
::part(badge) | The trailing badge. |
::part(children) | The nested children container. |
::part(spinner) | The spinner |
CSS custom properties
| Property | Description |
|---|---|
--nana-tree-connector | Colour of the vertical line joining nested nodes |
--nana-tree-indent | Indent added per nesting level |
--nana-tree-label-size | Node label text size |
--nana-tree-row-height | Height of a single node row |