Skip to content

Tree

Displays hierarchical data with support for selection, expansion, multi-select, lazy loading, and node drag-and-drop.

Basic Usage

Hierarchical tree

Click the expand arrow to show / hide child nodes; click a node label to select it.

Controlled Expansion and Selection

Initial expansion and selection

expanded controls the expanded nodes, selected controls the selected node.

Multi-Select

Checkable tree

Disabled Nodes

Disabled nodes

Lazy Loading

Lazy loading (async child fill-in on expand)

Click the expand arrow before "Folder A" to trigger loading

With lazy, nodes without children and not marked isLeaf / loaded are considered "not loaded": clicking the expand arrow emits oas-load (detail: { key }) and calls the load callback, and the host refills the child nodes and resets the data attribute. During loading, a loading placeholder is shown in place of the expand arrow; after the fill-in completes, the node auto-expands and the placeholder is removed. Nodes marked isLeaf: true do not show an expand arrow.

Node Drag and Drop

Draggable (reorder / reparent)

Drag a node to the upper / lower / middle of a target row to insert before / after / inside it

With draggable, nodes can be dragged to reorder or reparent: dropping on the upper half of a target row inserts before it (before), the lower half inserts after it (after), and the middle (when the target is expandable) moves it inside (inner). An insertion line and highlight feedback are shown during the drag; on release, oas-node-drop is emitted (detail: { dragKey, dropKey, position }), and the host updates the data and resets the data attribute. Dropping on empty tree space moves the node to the root (dropKey empty string, position: 'inner').

Large Data Sets (Virtual Scroll)

Virtual scroll with 10k nodes

Setting height enables virtualization (with a fixed row-height): the tree reuses oas-virtual-list to render only the nodes in the visible window. The expanded state is kept in the expanded attribute and survives scrolling and re-renders.

Events

Selection and check events

Selected: · Checked:

API

Attributes

AttributeDescriptionTypeDefault
checkableWhether to show checkboxesboolean
checkedSet of checked node keys (comma-separated)string
dataNode data [{ key, label, children?, disabled?, isLeaf?, loaded? }], JSON stringTreeNode[] | string[]
draggableNodes can be dragged to reorder / reparent; drop shows insertion line / highlight; release emits oas-node-dropboolean
expandedSet of expanded node keys (comma-separated)string
heightVirtual scroll viewport height (px); setting it enables virtualized rendering for large datastring360
lazyLazy loading: nodes without children and not marked isLeaf / loaded trigger loading on expandboolean
loadLazy loading callback (payload: { key }) => void, coexists with the oas-load event; the host refills child nodes and resets the data attribute(payload: { key: string }) => void
row-heightFixed row height when virtualized (px)string32
selectedKey of the selected nodestring

Events

EventDescription
oas-checkCheck state change, detail: { key, checked }
oas-loadLazy loading triggered, detail: { key }; the host refills children and resets the data attribute
oas-node-dropNode dropped, detail: { dragKey, dropKey, position }; position is before / after / inner; an empty-string dropKey means moved to the root
oas-selectNode selected, detail: { key, selected }

Node field notes: isLeaf: true marks an explicit leaf (no expand arrow under lazy loading); loaded: true marks a node as fully loaded (used with children to avoid triggering loading repeatedly).