Skip to content
Nana UI

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).

View .md Download

Svelte has no item component: NanaTree takes its nodes as an items array. See Tree.

npm install @nana-tec/ui-components

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.

<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

PropertyAttributeTypeDefaultDescription
badgebadgestring | undefined—Trailing badge text.
disableddisabledbooleanfalseDisabled — blocks selection, expansion, and keyboard interaction.
expandedexpandedbooleanfalseExpanded state of a branch node.
iconiconstring | undefined—Leading icon name (a nana-icon name).
labellabelstring''Plain-text label. Ignored when the label slot is used.
lazylazybooleanfalseTreat as a branch whose children load on first expand.
loadingloadingbooleanfalseShow a loading spinner in place of the chevron.
selectedselectedbooleanfalseSelected state (the tree controls this).

Methods

MethodDescription
collapse(): voidCollapse a branch.
expand(): voidExpand a branch, requesting a lazy load on first open.
toggle(): voidExpand the node if it is collapsed, collapse it if it is expanded

Events

EventDescription
nana-tree-item-activateInternal: row activated (handled by the tree).
nana-tree-item-toggleInternal: expanded state changed (handled by the tree).

Slots

SlotDescription
(default)Child nana-tree-item nodes.
labelRich label content (overrides the label attribute).

CSS parts

PartDescription
::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

PropertyDescription
--nana-tree-connectorColour of the vertical line joining nested nodes
--nana-tree-indentIndent added per nesting level
--nana-tree-label-sizeNode label text size
--nana-tree-row-heightHeight of a single node row