A tree view: a hierarchical list whose branches expand and collapse.
<.treeview id="notas" on_toggle="toggled" on_select="opened">
<.tree_item id="2026" label="Notas 2026" expanded>
<:icon><.icon name="folder" size="md" /></:icon>
<.tree_item id="out" label="Outubro" branch />
<.tree_item id="nfe" label="NF-e 48.211.xml" selected />
</.tree_item>
</.treeview>An item with children is a branch, one without is a leaf. branch draws a closed branch
before its children are there (loaded when it opens). checked (true, false or "mixed")
puts a checkbox before the label; chevrons={false} leaves the chevrons out.
Branches open and close in the browser (LedgerUI.Treeview hook), with no round trip; a
branch the person toggled stays that way across patches, and the server wins when it changes
expanded for it. on_toggle is pushed with %{"id" => id, "expanded" => boolean},
on_select with %{"id" => id} when a leaf is clicked (or gets Enter), on_check with
%{"id" => id, "checked" => boolean}; all to target when given. A %JS{} is executed instead.
The ARIA is rendered by the server: the root is role="tree", each row a role="treeitem" with
aria-selected, aria-expanded (branches), aria-checked (when checked is given), aria-owns
pointing at its role="group" of children and a roving tabindex (0 on the selected row, -1 on
the others; the hook makes sure one row, the first when none is selected, is in the tab order).
The hook only updates aria-expanded/aria-selected/tabindex as the person interacts.
The canvas look is flat rows: div.lu-tree-i, indented with an inline padding-left. Nested
tree_items are wrapped in a div.lu-tree-kids that indents them, so no depth is needed;
rows written side by side (as the design does) take depth.
Streams
<.treeview id="files" rows={@streams.files}>
<:row :let={{_dom_id, file}}>
<.tree_item id={"file-#{file.id}"} label={file.name} />
</:row>
</.treeview>
Summary
Functions
A tree written as data: the same as treeview/1 with one tree_item/1 per map.
Functions
A tree written as data: the same as treeview/1 with one tree_item/1 per map.
<.tree id="folders" items={[
%{id: "fiscal", label: "Fiscal", icon: "folder", count: 12, expanded: true,
children: [%{id: "nfe", label: "NF-e", icon: "file"}]}
]} selected="nfe" />Attributes
id(:string) - Defaults to"tree".items(:list) (required) - Maps with:labeland optionally:id,:icon,:count,:checked,:expandedand:children(the same shape, nested).selected(:any) - Theid(or thelabel, without ids) of the selected item. Defaults tonil.expanded(:list) - Ids of the branches that are open. Defaults to[].on_toggle(:any) - Defaults tonil.on_select(:any) - Defaults tonil.on_check(:any) - Defaults tonil.variant(:string) - Defaults to"canvas". Must be one of"canvas", or"lineone".chevrons(:boolean) - Defaults totrue.target(:any) - Defaults tonil.class(:any) - Defaults tonil.- Global attributes are accepted.
Attributes
id(:string) - Names the item in events and inexpanded. Defaults tonil.label(:string) - Defaults tonil.expanded(:boolean) - Defaults tofalse.selected(:boolean) - Defaults tofalse.branch(:boolean) - A branch even with no children yet. Defaults tofalse.checked(:any) - Defaults tonil.Must be one ofnil,true,false, or"mixed".tag(:string) - Wraps the item in this tag. Defaults tonil. Must be one ofnil,"li", or"div".count(:string) - A trailing count (the mono figure at the right). Defaults tonil.depth(:integer) - Indent level for rows written side by side. Defaults to0.chevron(:boolean) - Leaves room for / draws the chevron. Defaults totrue.chevron_class(:any) - Defaults tonil.class(:any) - Defaults tonil.- Global attributes are accepted.
icon="name"draws that icon before the label (the:iconslot takes any markup). Supports all globals plus:["icon"].
Slots
icon- An icon before the label.inner_block- The children; makes the item a branch.
Attributes
id(:string) (required)expanded(:list) - Ids of the branches that are open. Defaults to[].on_toggle(:any) - Defaults tonil.on_select(:any) - Defaults tonil.on_check(:any) - Defaults tonil.variant(:string) - Defaults to"canvas". Must be one of"canvas", or"lineone".chevrons(:boolean) - Defaults totrue.target(:any) - Defaults tonil.rows(:any) - A list or a stream rendered by:row. Defaults tonil.row_id(:any) - A function giving each row's DOM id (lists only). Defaults tonil.class(:any) - Defaults tonil.- Global attributes are accepted.
Slots
inner_blockrow- Renders one row; takes{dom_id, item}.