Reference

Tree

Nested items — files and folders, an outline — as a tree a keyboard can work: Up and Down through what shows, Right to open and go in, Left to close and go out (the other way round right to left), Home and End, a letter. row(item) { … } draws each; bind: holds the chosen item's key, or a list of keys with .multiple.

Tree(items: [Item], children: (Item) -> [Item]?, key: (Item) -> String or (Item) -> Number, …)

Since 6.2.0

multiple

label

  • src

  • App.wf

  • pages

  • Home.wf

  • About.wf

  • webfluent.app.json

Open: src/pages/Home.wf

Example

wf

state file = "src/pages/Home.wf" Tree(items: [ { path: "src", name: "src", children: [ { path: "src/App.wf", name: "App.wf" }, { path: "src/pages", name: "pages", children: [ { path: "src/pages/Home.wf", name: "Home.wf" }, { path: "src/pages/About.wf", name: "About.wf" }, ] }, ] }, { path: "webfluent.app.json", name: "webfluent.app.json" }, ], children: f => f.children ?? [], key: f => f.path, bind: file, open: ["src", "src/pages"], label: "Files") { row(f) { Icon(if f.children != null { "folder" } else { "file" }) Text(f.name) } } Text("Open: {file}").muted

Several chosen

wf

state picked: [String] = [] Tree(items: [ { id: "eu", name: "Europe", children: [{ id: "fra1", name: "Frankfurt" }, { id: "lhr1", name: "London" }] }, ], children: r => r.children ?? [], key: r => r.id, bind: picked, label: "Regions").multiple { row(r) { Text(r.name) } }

Props

Props of Tree
PropTypeUnsetMeaning

items:

[Item] (required)

—

The items at the top level

children:

(Item) -> [Item]? (required)

—

An item's children: f => f.children; null or an empty list for a leaf

key:

(Item) -> String or (Item) -> Number (required)

—

What tells two items apart: f => f.path; what bind: and open: hold

bind:

State

none: nothing is chosen

The state holding the chosen item's key, written on Enter, Space or a press; with .multiple, a list of keys

multiple:

Bool

false

Several chosen at once: Space, Shift with an arrow, Ctrl or ⌘ with A; bind: holds a list. Written as a flag, .multiple, or multiple: true.

open:

[String] or [Number]

[]: all closed

The keys of the items open when it is first drawn

label:

String (required)

—

What the tree is, its accessible name

Attribute families: global, aria, data. Plus the 22 universal props every element takes: animate:, exit:, speed:, duration:, delay:, easing:, stagger:, on:, count:, shared:, class:, ref:, drag:, dragGroup:, dropValue:, dropAxis:, dropInside:, roving:, trapFocus:, mount:, update:, cleanup:.

Flags and cases

A flag is written after the parentheses with a dot: a Bool prop, or a case of one of the element's enum props. A case the enum lacks is an error with a hint.

.multiple

Events

Every element also takes the props, the events and the attribute families listed on every element.

Slots

It takes no slots.

Renders with the class wf-tree, stable across releases, so a stylesheet may target it.