Help us shape the future of Go! Take the 2026 Go Developer Survey

tree

package
v0.71.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package tree provides a TreeView component built on the WAI-ARIA tree pattern. The Go-side renders the SSR-visible portion of the tree as nested <ul role="group">/<li role="treeitem"> elements. The runtime (core-ui/runtime/runtime.js) wires keyboard navigation, ArrowUp/Down/Left/Right, Home, End, Enter/Space, type-ahead, and drives expand/collapse through existing data-fui-rpc + signal machinery.

Children may be:

  • Rendered statically up-front (Children populated).
  • Lazy-loaded on expand (Children empty, LazyPath set). Pressing ArrowRight or Enter on a collapsed node clicks the node's toggle button (data-fui-tree-toggle), which fires an RPC to LazyPath. The server returns the inner HTML of the child <ul role="group">, swapped in via the signal binding.

Index

Constants

This section is empty.

Variables

View Source
var Style = registry.RegisterStyle("tree", styleFn)

Style is the registered stylesheet handle. CSS auto-loads on first appearance via the runtime's data-fui-comp scanner. Apps override the visual defaults via theme tokens.

Functions

func Render

func Render(cfg Config) render.HTML

Render renders the tree. The first visible treeitem carries tabindex=0 so Tab from the page lands on the tree; all other treeitems get tabindex=-1 (roving tabindex per WAI-ARIA tree).

Types

type Config

type Config struct {
	// ID is the wrapper id. Required.
	ID string

	// Label is the aria-label on the role="tree" wrapper. Required.
	Label string

	// Nodes are the root-level nodes. Required.
	Nodes []Node

	// SignalPrefix names the signal namespace used for lazy-load
	// signal bindings, each LazyPath branch's child <ul role="group">
	// is bound to data-fui-signal="<prefix>-<node-id>". Required when
	// any node uses LazyPath; ignored otherwise.
	SignalPrefix string

	// Class is added to the tree wrapper.
	Class string
}

Config configures the tree wrapper.

type Node

type Node struct {
	// ID is unique within the tree. Required.
	ID string

	// Label is the visible text. Required.
	Label string

	// Href, when set, makes the leaf label a link. Mutually
	// exclusive with Children/LazyPath.
	Href string

	// Children are statically-known descendants. Empty for leaves.
	Children []Node

	// LazyPath, when set, makes this a branch whose children load
	// on first expand via an RPC POST. Mutually exclusive with
	// Children, if both are set, Children wins on first render and
	// LazyPath is ignored (the children are already there).
	LazyPath string

	// Expanded forces this branch open on first paint. Default false.
	Expanded bool

	// Selected sets aria-selected="true" on the treeitem.
	Selected bool
}

Node is one entry in the tree.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL