Documentation
Concepts

State attributes

Every data-* attribute the primitives set, what it means and where it appears, plus the --tree-depth custom property for the indentation.

The primitives expose their state as data-* attributes, present (empty, or with a value) or absent, and never "false". Style them with attribute selectors (.row[data-selected]) or Tailwind's data variants (data-selected:bg-blue-50, data-[drop-position=inside]:ring-2).

On every part of an item

Tree.Item, Tree.ItemContent, Tree.Group and Tree.Toggle carry their item's state, so each row styles itself without reaching for an ancestor (a selected parent never leaks into its children's rows). Your own check control reads the same state (useTreeItem(item).state) and puts the attributes it styles with on itself.

attributewhen
data-expandedthe item's children are shown
data-selectedthe item is part of the selection
data-focusedthe item is the focused item (the roving tab stop, model state; use :focus-visible for DOM focus)
data-checkedits checkbox is checked
data-indeterminateits checkbox is mixed: only some of its descendants are checked
data-renamingits label is being edited
data-loadingits children are being loaded
data-load-errorthe last load of its children failed
data-disabledit is disabled: focusable, not actionable
data-leafit has no children and no children status
data-draggingit is being dragged
data-drop-targetthe drop target of the drag under way is relative to it
data-drop-positionwhile it is the drop target: before, after or inside
data-depthits depth: 0 for a root item (also on DropIndicator, the level the drop lands on)

On the root

attributewhen
data-dragginga drag is under way (pointer or keyboard, dragAndDrop()), or foreign content (foreignDrop()) is dragged over the tree
data-keyboard-dragginga keyboard drag is under way
data-dragging-from-other-treea drag from another tree of the drag group is under way
data-emptythe tree has no item

Tree.Root also sets aria-multiselectable when the selection mode is multiple.

On the other parts

attributeonwhen
data-drop-positionDropIndicatorwhere the drop goes: before, after or inside
data-invalidyour input, from useTreeItemRename's propsthe last commit was refused (with aria-invalid)

ARIA

The ARIA attributes are state too, and selecting on them keeps styles and semantics together: [aria-expanded="true"], [aria-selected="true"], [aria-checked="mixed"], [aria-disabled="true"], [aria-busy="true"] on Tree.Item.

The depth

Every part of an item sets --tree-depth (an inline custom property: 0 for a root item) for the indentation: padding-inline-start: calc(var(--tree-depth) * 1rem). See Styling the depth.

Focus

The item is the element that takes DOM focus, and its row is inside it: draw the focus ring on the row with .item:focus-visible > .row (Tailwind: [:focus-visible>&]:ring-2 on the row). data-focused marks the roving tab stop even when the tree does not have focus.