Tree

Tree

HkTree is the library's nested row view: you hand it an array of nodes ({ id, label, children } plus four paint fields), and it renders one div.hk-tree-row per visible node, recursing only into the nodes that are open. Each row is a chevron toggle, an optional leading icon, and a label — or, with tag / tagLabel, a toned chip beside or instead of that label. The same stylesheet ships on both sides (HkTree.scss, vendored into the Rust crate and drift-guarded), so the two forms paint identically.

  • A node whose content is JSON — showing an object or array with type hints and copy-on-click — is JsonTree; this page is the general row tree.
  • The legacy Rust tree surfaces (TreeNode, VirtualTree, DragDropTree) are separate components with their own data types and no Vue counterpart; Tree is the one both languages ship.
  • The row grammar is the same one NavItem uses for sidebar links — chevron cell, 16px icon cell, ellipsized label — but a nav row navigates and a tree row opens.

Import

tsx
1
import { HkTree, type TreeNode, type TreeSize } from "@celestia-island/hikari";
rust
1
2
use hikari_components::*;          // Tree, TreeItem, TreeSize, TreeSelectionState
use hikari_components::prelude::*; // TreeProps, rsx!, VNode, Icon, MdiIcon

The Rust form is a plain function, Tree(TreeProps { … }), and it is a controlled component: Vue keeps its open set in a local ref<Set>, the mirror takes it as the expanded_keys prop and reports every transition through on_toggle. TreeItem (the row data) and the tree_* helpers are published by the crate root only — they are not in the prelude, so the import block above matters. Inside rsx! every prop may be omitted, including nodes; an empty tree renders the root and nothing else.

Expanding and collapsing

In Vue the open set is private: expanded is a ref<Set<string>> created at setup, the chevron press flips it and emits toggle with the node payload, and no prop can read or seed it except defaultExpandAll, which seeds every parent once — the walk runs on mount and again whenever nodes changes, but ensureExpanded bails out as soon as the set is non-empty (if (expanded.value.size > 0) return;). Collapse everything by hand and the next nodes update re-expands the whole tree; mutate the array in place and the watch never fires at all.

The mirror cannot keep that set either (a use_signal allocates a fresh signal on every render), so expanded_keys is the state and on_toggle hands you the pressed row's id. Vue's defaultExpandAll has no prop counterpart — a controlled component cannot seed itself — so call tree_expandable_keys(&nodes) once and pass the result as expanded_keys; it is the same document-order walk Vue runs, and it includes a lazy parent that has nothing loaded yet.

App
API
Worker
Jobs
Docs

The snapshot above is a still: the Rust form draws the open state it is handed and runs nothing. Vue converts one of these two states from the other with a press — that is the interaction below, not a second example.

Click behaviour and selection

A row press emits select with the node payload; with expandOnClick it also toggles a parent, so the same press both selects and opens. The chevron press is separate and stops propagation (the row handler never sees it), so a chevron press toggles without selecting.

The mirror keeps the two names but changes the payload to the row id (on_select / on_toggle, both EventHandler<String>), and adds a selection state Vue does not have: Vue only emits, it paints nothing and keeps no set. selected_keys is a controlled prop, a selected row reports data-selected and aria-selected="true", and a parent rolls its subtree up through tree_selection_state onto data-selection="all|partial". Both markers are paint-inert — the canonical sheet has no selected-row or checkbox rule — so there is no checkbox markup on the row; take the subclass to paint the state yourself.

App
Docs

Status, chips and sizes

status is a free-form paint token that lands on the row as data-status; the sheet knows six of them — completed (dimmed, struck-through label), failed (danger text), in_progress / running (medium weight), warning (warning text) and muted (dimmed) — and any other string is simply inert. tag turns the label itself into a chip, tagLabel keeps the plain label and prepends a chip; when both are set tagLabel wins. size is xs / sm / md and defaults to sm on both sides (row height 22 / 28 / 34px, label 0.75 / 0.75 / 0.875rem).

On the Rust side the types differ rather than the behaviour: icon is a typed MdiIcon drawn at Vue's size: 13 instead of a component, a TreeItem is a Vec<TreeItem> of children instead of an optional array, and the legacy TreeNodeData::disabled field is gone — Vue expresses "inactive" with status, which the sheet actually paints.

v2 Build
Lint
Tests
Draft
v2 Build
Lint
Tests
Draft

Interaction: the chevron, and the cursor the mirror adds

Vue has no keyboard support at all: the tree root does not take focus, rows are plain divs, and the only way to open a node is its chevron. The mirror adds the standard tree cursor on the focusable root (role="tree", tabindex="0", aria-activedescendant pointing at the host-prefixed row id): ArrowDown / ArrowUp walk the flattened list without wrapping, ArrowRight opens a closed parent and otherwise steps into an open one, ArrowLeft closes an open parent and otherwise steps out to it, Home / End jump to the ends, and Enter or Space select. The resolution lives in tree_keydown_action and is reported through on_active_change; id_prefix keeps the row ids unique when several trees share a page.

A row click also reports the active row, so the cursor follows the pointer and a host never wires the two separately.

TSX
press a chevron
App
Docs

The Rust form is declarative only — the snapshot runs no handler — so the same states are reached by passing the props the host would have stored.

Lazy loading and the visible list

Lazy loading is a mirror extension: Vue always receives the whole tree. A node built with .expandable() is declared as a parent with nothing loaded yet, renders the parent chevron, and an expansion request on it emits on_load once while lazy is on — the only fetch trigger. loading_keys marks the rows being fetched as data-loading, which is paint-inert (the sheet has no spinner). Nothing is allocated or remembered inside the component: the host fills children and drops the key. tree_ancestor_path gives the ancestors of a node so a host can open the chain to it; tree_subtree_keys gives a node's whole subtree, which is what the selection roll-up consumes.

Rust
App
API
Worker
Docs
App
API
Worker
Docs

API

Vue

Props

NameTypeDefaultRequired
nodesArray as PropType<TreeNode[]>() => []—
sizeString as PropType<TreeSize>"sm"—
defaultExpandAllBooleanfalse—
indentNumber16—
expandOnClickBooleanfalse—

Emits

EventPayload
selectTreeNode
toggleTreeNode

Rust

Props — Tree

PropTypeDefaultDescription
nodesVec<TreeItem>[]The roots (Vue: nodes, default []).
sizeTreeSizeTreeSize::SmSize step, carried as the root's data-size.
indentu3216Indent step in px (Vue: indent, default 16).
expand_on_clickboolfalseA row click also toggles a parent (Vue: expandOnClick).
expanded_keysVec<String>[]Controlled open ids (Vue: the local expanded set).
selected_keysVec<String>[]Controlled selected ids (mirror extension — Vue emits select only).
active_keyOption<String>NoneThe keyboard cursor's row (mirror extension).
lazyboolfalseLazy-load shell: an expansion request on an unloaded parent emits TreeProps::on_load.
loading_keysVec<String>[]Rows whose children the host is fetching (data-loading).
id_prefixString""Prefix for the row ids (id_prefix + item.id), so several trees on one page keep aria-activedescendant unique.
on_toggleOption<EventHandler<String>>NoneFires with the toggled row id (Vue: the toggle emit, node payload).
on_selectOption<EventHandler<String>>NoneFires with the selected row id (Vue: the select emit, node payload).
on_active_changeOption<EventHandler<String>>NoneFires with the row id the cursor moved to (mirror extension).
on_loadOption<EventHandler<String>>NoneFires with a lazy parent's id when its children should be fetched (mirror extension).
classString""Appended to div.hk-tree.

Accessibility

  • The root is role="tree" with tabindex="0" and no accessible name of its own — there is no aria-label prop, so the tree is announced as an unnamed tree. Name it from the surrounding heading or put the label in the host's own markup above it.
  • Each row is role="treeitem" with aria-level. Children of an open node live in a div.hk-tree-children and are not wrapped in role="group", so assistive technology gets the level number but not a declared group boundary; the guide line is decorative CSS.
  • The chevron span has no aria-expanded and no label in either form: the open state is the data-open attribute and a rotated glyph, which is visual only. A screen-reader user on the Rust side can still reach the state through the tree cursor (ArrowRight / ArrowLeft); in Vue there is no keyboard path at all.
  • In Vue nothing in the tree is focusable — the root takes no tab stop and no row is a control — so a Vue tree is pointer-only. The mirror's focusable root, aria-activedescendant and cursor are the accessible path, and aria-selected / data-selected are the only announced selection facts.
  • The icon cell is a decorative glyph with no label, and a status row is announced only as its label text: completed / failed / muted never become words, so a host that needs the state spoken must put it in the label or a sibling text.

Related components

  • JsonTree — the same row grammar applied to a JSON payload: containers, type hints and copy-on-click.
  • NavItem — the sidebar row, with link and accordion branches instead of tree semantics.
  • TreeNode — the legacy Rust-only node with its own arrow / content / label parts.
  • DragDropTree — the legacy Rust-only reorder surface, when rows must be moved as well as opened.