1. framework components
  2. tree view

Tree View

Used to display hierarchical data.

File System

package.json

Controlled

File System

package.json

Multiple Selection

  • Windows: Hold Ctrl + left click with mouse.
  • MacOS: Hold + left click with mouse.

File System

package.json

Collapse and Expand

Use the Provider Pattern to gain access to the collapse and expand methods on the TreeView instance.

File System

package.json

Lazy Loading

File System

package.json

API Reference

Root

txt
w-full space-y-2 select-none
PropDefaultType
collectionTreeCollection<T> | undefined

The tree collection data

idsPartial<{ root: string; tree: string; label: string; node: (value: string) => string; }> | undefined

The ids of the tree elements. Useful for composition.

expandedValuestring[] | undefined

The controlled expanded node ids

defaultExpandedValuestring[] | undefined

The initial expanded node ids when rendered. Use when you don't need to control the expanded node value.

selectedValuestring[] | undefined

The controlled selected node value

defaultSelectedValuestring[] | undefined

The initial selected node value when rendered. Use when you don't need to control the selected node value.

defaultCheckedValuestring[] | undefined

The initial checked node value when rendered. Use when you don't need to control the checked node value.

checkedValuestring[] | undefined

The controlled checked node value

defaultFocusedValuestring | null | undefined

The initial focused node value when rendered. Use when you don't need to control the focused node value.

focusedValuestring | null | undefined

The value of the focused node

selectionMode"single""single" | "multiple" | undefined

Whether the tree supports multiple selection - "single": only one node can be selected - "multiple": multiple nodes can be selected

onExpandedChange((details: ExpandedChangeDetails<T>) => void) | undefined

Called when the tree is opened or closed

onSelectionChange((details: SelectionChangeDetails<T>) => void) | undefined

Called when the selection changes

onFocusChange((details: FocusChangeDetails<T>) => void) | undefined

Called when the focused node changes

onCheckedChange((details: CheckedChangeDetails) => void) | undefined

Called when the checked value changes

canRename((node: T, indexPath: IndexPath) => boolean) | undefined

Function to determine if a node can be renamed

onRenameStart((details: RenameStartDetails<T>) => void) | undefined

Called when a node starts being renamed

onBeforeRename((details: RenameCompleteDetails) => boolean) | undefined

Called before a rename is completed. Return false to prevent the rename.

onRenameComplete((details: RenameCompleteDetails) => void) | undefined

Called when a node label rename is completed

onLoadChildrenComplete((details: LoadChildrenCompleteDetails<T>) => void) | undefined

Called when a node finishes loading children

onLoadChildrenError((details: LoadChildrenErrorDetails<T>) => void) | undefined

Called when loading children fails for one or more nodes

expandOnClicktrueboolean | undefined

Whether clicking on a branch should open it or not

typeaheadtrueboolean | undefined

Whether the tree supports typeahead search

loadChildren((details: LoadChildrenDetails<T>) => Promise<T[]>) | undefined

Function to load children for a node asynchronously. When provided, branches will wait for this promise to resolve before expanding.

dir"ltr""ltr" | "rtl" | undefined

The document's text/writing direction.

getRootNode(() => ShadowRoot | Node | Document) | undefined

A root node to correctly resolve document in custom environments. E.x.: Iframes, Electron.

element((attributes: HTMLAttributes<"div">) => Element) | undefined

Render the element yourself

Provider

PropDefaultType
valueTreeViewApi<PropTypes, any>

element((attributes: HTMLAttributes<"div">) => Element) | undefined

Render the element yourself

Context

PropDefaultType
children(treeView: TreeViewApi<PropTypes, any>) => ReactNode

Tree

txt
space-y-1
PropDefaultType
element((attributes: HTMLAttributes<"div">) => Element) | undefined

Render the element yourself

Label

txt
label-text
PropDefaultType
level1 | 2 | 3 | 4 | 5 | 6 | undefined

The level of the heading.

element((attributes: HTMLAttributes<"h3">) => Element) | undefined

Render the element yourself

NodeProvider

PropDefaultType
valueNodeProps

childrenReactNode

Branch

txt
space-y-1
PropDefaultType
element((attributes: HTMLAttributes<"div">) => Element) | undefined

Render the element yourself

BranchControl

txt
flex items-center gap-2 pe-4 py-2 rounded-base hover:preset-tonal data-selected:preset-filled ps-[calc(var(--depth)*var(--spacing)*6-var(--spacing)*2)]
PropDefaultType
element((attributes: HTMLAttributes<"div">) => Element) | undefined

Render the element yourself

BranchText

txt
flex items-center gap-2
PropDefaultType
element((attributes: HTMLAttributes<"span">) => Element) | undefined

Render the element yourself

BranchIndicator

txt
data-[state=open]:rotate-90
PropDefaultType
element((attributes: HTMLAttributes<"span">) => Element) | undefined

Render the element yourself

BranchContent

txt
space-y-1 relative
PropDefaultType
element((attributes: HTMLAttributes<"div">) => Element) | undefined

Render the element yourself

BranchIndentGuide

txt
absolute bg-surface-500/50 w-0.5 h-full rounded-base left-[calc(var(--depth)*var(--spacing)*6)] -translate-x-1/2
PropDefaultType
element((attributes: HTMLAttributes<"div">) => Element) | undefined

Render the element yourself

Item

txt
flex items-center gap-2 pe-4 py-2 rounded-base hover:preset-tonal data-selected:preset-filled ps-[calc(var(--depth)*var(--spacing)*6+var(--spacing)*4)]
PropDefaultType
element((attributes: HTMLAttributes<"div">) => Element) | undefined

Render the element yourself

View page on GitHub