Tree
Hierarchical lists built on headless-tree with expandable folders, selection, and drag-and-drop.
Basic tree
Expandable folders rendered from a flat tree.getItems() list. Folder rows with children get a chevron that expands and collapses them. Leaf rows are padded past the chevron column.
Indentation
indent sets the width of each nesting level in pixels. The default is 16; this preview uses 24.
Tree with selection
Selection state stays in the consumer. Folders expand via the chevron; leaf rows handle selection. Call event.preventDefault() in a row's onClick to skip the default headless-tree click behavior.
Tree with drag and drop
Enable dragAndDropFeature on the headless-tree instance and render TreeDragLine inside the tree container. The container needs relative so the line lines up with the rows. Moving the data is up to the onDrop handler you pass to useTree; this preview only shows the drop line.
Usage
TreeItemLabel reads the item from the surrounding TreeItem and shows item.getItemName() when it has no children.
Tree
The headless-tree instance returned by useTree
Width of each nesting level in pixels
Default: 16
Positions rows relatively so a consumer can draw guide lines. It draws no lines itself.
Default: false
Icon used by the folder toggle in TreeItemLabel
Default: chevron
Accessible label for the tree
Render the child element instead of a div
Default: false
Additional CSS classes to apply to the tree container
TreeItem
The headless-tree item to render
Row content, usually a TreeItemLabel
Blocks clicks and keyboard actions and removes the row from the tab order
Default: false
Replaces the default expand and collapse for the toggle button and the left and right arrow keys
Runs before the headless-tree click handler. Call preventDefault to skip it
Render the child element instead of a div
Default: false
Additional CSS classes to apply to the row
TreeItemLabel
The item to label. Defaults to the item of the surrounding TreeItem
Label content. Defaults to item.getItemName()
Replaces the default expand and collapse when the folder toggle is clicked
Render the child element instead of a span
Default: false
Additional CSS classes to apply to the label
Other exports
Drop position indicator. Renders nothing unless the tree uses dragAndDropFeature
headless-tree features re-exported for useTree