Documentation
API: primitives (@fragiola/tree-react, @fragiola/tree-vue, @fragiola/tree-angular)

Tree.Item

An item of the tree (role treeitem) with its level, position, state and roving tab stop. It is the element DOM focus goes to.

Tree.Item is the role="treeitem" element of the WAI-ARIA APG tree view: it carries aria-level, aria-posinset, aria-setsize, aria-expanded (a parent), aria-selected (with the selection() feature), aria-checked (a root with checkboxes), aria-disabled and aria-busy (while its children load), and the roving tabindex (0 on the one tab stop, -1 elsewhere). It is the element DOM focus goes to, and it provides its item to the parts inside it.

function FileItem({ item }: { item: ItemOf<Types> }) {
    return (
        <Tree.Item item={item} aria-label={item.label} className="item">
            <Tree.ItemContent className="row">{item.label}</Tree.ItemContent>
            <Tree.Group<Types>>{(child) => <FileItem item={child} />}</Tree.Group>
        </Tree.Item>
    );
}

Its element holds the row and the group of children: style the row (Tree.ItemContent), and draw the focus ring through the item (.item:focus-visible > .row). It is useTreeItem on a div (Hooks).

Props

ItemProps<T> extends the common primitive props (on a div), with the item's state (TreeItemState) for render, className and style.

proptypedescription
itemItemOf<T>the item, as Tree.Items or Tree.Group gives it
childrenReactNodeits row (Tree.ItemContent) and its group (Tree.Group); no text of its own

State

TreeItemState: its place in the tree (itemId, path, level, posinset, setsize) and its state (expanded, selected, focused, tabStop, checkState, checked, indeterminate, renaming, loading, loadError, disabled, leaf, dragging, dropTarget, dropPosition). Every part of an item gets the same state; each field is described on Hooks.

Attributes

attributewhen
role="treeitem"always
aria-level, aria-posinset, aria-setsizealways: 1 for a root item; its position among its siblings, from 1; how many siblings it has
aria-expandeda parent: true or false
aria-selectedthe selection() feature, in a mode other than none (the features' ARIA and data-* are model state: model.get("item-attributes-by", { itemId }), a server render has them)
aria-checkedthe root has checkboxes: true, false or "mixed"
aria-disabledthe item is disabled
aria-busyits children are loading
tabindex0 on the roving tab stop, -1 on every other item
data-tree-part="item"always
data-tree-pathalways: its position from the root, /0/2
the item's data-* stateState attributes

Structural style: --tree-depth (0 for a root item).

Behaviour

  • Focus entering its element makes it the focused item (item.focus).
  • It registers its element with the engine, which moves DOM focus to it.