Navigated to /docs/ui/components/tree-view

TreeView

Keyboard-accessible hierarchical view with multi-selection and drop states.

Preview

A live, theme-aware example rendered with the published component.

Loading preview…

Import

Import from the focused entry point below, or use the same named export from @tavojs/ui. Both are public APIs; measure the built application when comparing their bundle cost.

TSX
tsximport { TreeView } from "@tavojs/ui/tree-view";

The component import loads compiled component CSS. Enable tavoUi() for your project theme variables, or import @tavojs/ui/theme.css once for the package default theme. The equivalent CSS-safe component alias is @tavojs/ui/css/tree-view.

When to use

Use it when

Use `TreeView` for hierarchical content that needs roving focus, single or multiple selection, expansion, activation, and generic drop feedback

Choose something else when

Avoid TreeView when using data components as decorative layout containers.

Examples

These examples include imports and local state where interaction requires it. Render the exported component in a page after completing UI installation. Demo state stays in the mounted component; connect file handling, persistence, and data loading to your application as needed.

TreeView example

TSXCreate: src/components/examples/TreeViewExample1.tsx
tsximport { createTavo } from "@tavojs/core";
import { TreeView } from "@tavojs/ui/tree-view";
import { Text } from "@tavojs/ui";

type State = { selectedIds: string[] };

export const TreeViewExample1 = createTavo<Record<string, never>, State>({
  model: () => ({ selectedIds: [] }),
  view: ({ state, model }) => (
    <>
      <TreeView
        aria-label="Page layers"
        selectedIds={state.selectedIds}
        selectionMode="multiple"
        defaultExpandedIds={["hero"]}
        onSelectionChange={(selectedIds) => model.set("selectedIds", selectedIds)}
      >
        <TreeView.Item id="hero" label="Hero" description="Section">
          <TreeView.Item id="heading" label="Heading" />
        </TreeView.Item>
      </TreeView>
      <Text>Selected: {state.selectedIds.join(", ") || "None"}</Text>
    </>
  )
});

Common props and defaults

A curated starting point. The complete TypeScript API below includes additional props and compound member contracts.

PropTypeDefaultDescription
classNamestring

Optional class hook applied to the public root element owned by the component.
selectedIdsreadonly string[]

Controlled selected identifiers.
defaultSelectedIdsreadonly string[]

Initial selection.
selectionMode"none" | "single" | "multiple"

Selection behavior.
selectionAnchorIdstring

Explicit contiguous-range anchor.
expandedIdsreadonly string[]

Controlled expanded identifiers.
onSelectionChange(ids: string[]) => void

Selection callback.
onActivate(id: string) => void

Enter or double-click activation.
onDrop(event: TreeViewDropEvent) => void

Opaque in-memory source/target drop request.

Complete TypeScript API

Import from @tavojs/ui/tree-view. Published exports: Tree, TreeItem, TreeView, TreeViewDropEvent, TreeViewDropPlacement, TreeViewDropState, TreeViewItem, TreeViewItemProps, TreeViewProps, TreeViewRoot, TreeViewSelectionMode, nextTreeSelection.

TreeViewProps

PropertyTypeRequiredDescription
childrenChild

No

Inherited children attribute accepted by TreeView.

classNamestring

No

Optional class hook applied to the public root element owned by the component.

sxSx

No

Inherited sx attribute accepted by TreeView.

idstring

No

Inherited id attribute accepted by TreeView.

rolestring

No

Inherited role attribute accepted by TreeView.

styleRecord<string, unknown>

No

Inherited style attribute accepted by TreeView.

titlestring

No

Inherited title attribute accepted by TreeView.

tabIndexnumber

No

Inherited tabIndex attribute accepted by TreeView.

hiddenboolean

No

Inherited hidden attribute accepted by TreeView.

disabledboolean

No

Inherited disabled attribute accepted by TreeView.

onClickTavoEventHandler<MouseEvent>

No

Inherited onClick attribute accepted by TreeView.

onChangeTavoEventHandler<Event>

No

Inherited onChange attribute accepted by TreeView.

onInputTavoEventHandler<Event>

No

Inherited onInput attribute accepted by TreeView.

onKeyDownTavoEventHandler<KeyboardEvent>

No

Inherited onKeyDown attribute accepted by TreeView.

onFocusTavoEventHandler<FocusEvent>

No

Inherited onFocus attribute accepted by TreeView.

onBlurTavoEventHandler<FocusEvent>

No

Inherited onBlur attribute accepted by TreeView.

selectedIdsreadonly string[]

No

Controlled selected identifiers.

defaultSelectedIdsreadonly string[]

No

Initial selection.

selectionModeTreeViewSelectionMode

No

Selection behavior.

selectionAnchorIdstring

No

Explicit contiguous-range anchor.

expandedIdsreadonly string[]

No

Controlled expanded identifiers.

defaultExpandedIdsreadonly string[]

No

Inherited defaultExpandedIds attribute accepted by TreeView.

onSelectionChange(selectedIds: string[]) => void

No

Selection callback.

onExpandedChange(expandedIds: string[]) => void

No

Inherited onExpandedChange attribute accepted by TreeView.

onActivate(id: string) => void

No

Enter or double-click activation.

onDrop(event: TreeViewDropEvent) => void

No

Opaque in-memory source/target drop request.

TreeViewItemProps

PropertyTypeRequiredDescription
childrenChild

No

Inherited children attribute accepted by TreeView.

classNamestring

No

Optional class hook applied to the public root element owned by the component.

sxSx

No

Inherited sx attribute accepted by TreeView.

idstring

Yes

Inherited id attribute accepted by TreeView.

rolestring

No

Inherited role attribute accepted by TreeView.

styleRecord<string, unknown>

No

Inherited style attribute accepted by TreeView.

titlestring

No

Inherited title attribute accepted by TreeView.

tabIndexnumber

No

Inherited tabIndex attribute accepted by TreeView.

hiddenboolean

No

Inherited hidden attribute accepted by TreeView.

disabledboolean

No

Inherited disabled attribute accepted by TreeView.

onClickTavoEventHandler<MouseEvent>

No

Inherited onClick attribute accepted by TreeView.

onChangeTavoEventHandler<Event>

No

Inherited onChange attribute accepted by TreeView.

onInputTavoEventHandler<Event>

No

Inherited onInput attribute accepted by TreeView.

onKeyDownTavoEventHandler<KeyboardEvent>

No

Inherited onKeyDown attribute accepted by TreeView.

onFocusTavoEventHandler<FocusEvent>

No

Inherited onFocus attribute accepted by TreeView.

onBlurTavoEventHandler<FocusEvent>

No

Inherited onBlur attribute accepted by TreeView.

labelChild

Yes

Inherited label attribute accepted by TreeView.

descriptionChild

No

Inherited description attribute accepted by TreeView.

depthnumber

No

Inherited depth attribute accepted by TreeView.

draggableboolean

No

Inherited draggable attribute accepted by TreeView.

expandedboolean

No

Inherited expanded attribute accepted by TreeView.

dropStateTreeViewDropState

No

Inherited dropState attribute accepted by TreeView.

expandLabelstring

No

Inherited expandLabel attribute accepted by TreeView.

State ownership and DOM target

ConcernContract
StateSelection and expansion are independent. Use selectedIds/onSelectionChange and expandedIds/onExpandedChange, or their defaultSelectedIds/defaultExpandedIds initial values.
DOM targetPublic passthrough props target the component root. Treat nested elements and private class names as implementation details.

Anatomy and related components

Public compound members: Root, Item

Limitations

Avoid TreeView when using data components as decorative layout containers.

Use only the documented props, entry points, and compound members. Internal DOM nesting and CSS class names can change without becoming part of the public component contract.

Accessibility

Items use ARIA tree semantics and roving tab stops. Arrow, Home, End, Space, and Enter behavior is keyboard complete; expansion buttons are separately named.

  • Items use ARIA tree semantics and roving tab stops. Arrow, Home, End, Space, and Enter behavior is keyboard complete; expansion buttons are separately named.

Component status

ContractCurrent value
Maturitystable
Categorydata
Component import@tavojs/ui/tree-view
Explicit CSS import@tavojs/ui/css/tree-view
PreviewInteractive preview available on this page