Skip to content

TreeView

Introduction

The TreeView component provides a hierarchical, interactive navigation structure for displaying nested data such as file systems, categories, organization charts, and more. It supports selection (single/multi), expansion/collapse, checkboxes, custom icons, drag-and-drop, and accessibility features. Designed for both simple and complex trees, it adapts to a wide range of use cases in dashboards, explorers, and admin panels.

Import

ts
import { TreeView } from '@odyssee/components';

LiveCodeEditor examples

Basic TreeView

Code Éditable
Résultat

Multi-select TreeView

Code Éditable
Résultat

TreeView with Checkboxes

Code Éditable
Résultat

TreeView with Custom Icons

Code Éditable
Résultat

TreeView with Lines and Right Icons

Code Éditable
Résultat

Controlled Expansion

Code Éditable
Résultat

Props

PropTypeDefaultDescription
nodesTreeView.Node[]Array of tree nodes (see below for structure).
selectablebooleanfalseEnables node selection.
multiSelectbooleanfalseEnables multi-selection (shift/ctrl).
selectedstring[] | Signal<string[]>Controlled selected node values.
onSelect(selected: string[]) => voidCallback when selection changes.
expandedstring[] | Signal<string[]>Controlled expanded node values.
onExpand(expanded: string[]) => voidCallback when expansion changes.
alwaysOpenbooleanfalseKeeps all nodes expanded.
showCheckboxesbooleanfalseShows checkboxes for each node.
checkedstring[] | Signal<string[]>Controlled checked node values.
onCheck(checked: string[]) => voidCallback when checked nodes change.
draggablebooleanfalseEnables drag-and-drop (requires Sortable.js).
onDragEnd(nodes: TreeView.Node[]) => voidCallback when drag-and-drop ends.
showLinesbooleanfalseShows vertical connection lines between nodes.
iconPosition"left" | "right""left"Position of node icons.
ariaLabelstringARIA label for accessibility.
ariaLabelledBystringARIA labelledby for accessibility.
classNamestringAdditional CSS classes for the root element.
idstringauto-generatedID for the treeview component.
styleobjectInline styles for the root element.
...restBaseComponentPropsAny other base props supported by Odyssee components.

TreeView.Node

PropTypeDescription
valuestringUnique identifier for the node.
labelstringDisplay text for the node.
isDirbooleanMarks node as a folder (true) or file (false/absent).
iconPulse.JSX.Element | stringCustom icon for the node (emoji, SVG, etc.).
disabledbooleanDisables the node.
childrenTreeView.Node[]Array of child nodes.

Implementation notes

  • The component supports both controlled and uncontrolled selection, expansion, and checked states via Pulse signals.
  • Multi-select uses shift/ctrl for range and additive selection.
  • Checkboxes allow for independent checked state per node.
  • Custom icons can be set per node; folders/files have default icons if not specified.
  • Drag-and-drop is supported (requires Sortable.js integration).
  • Vertical connection lines can be enabled for classic tree appearance.
  • Icon position can be set to left or right.
  • Designed for both light and dark themes.
  • All nodes and interactions are accessible and keyboard-navigable.

Accessibility

  • Tree structure uses ARIA roles (tree, treeitem, group) for screen readers.
  • Keyboard navigation is supported (Arrow keys, Home/End, Space/Enter for selection).
  • Focus and selected states are clearly styled.
  • Checkboxes use proper ARIA attributes.
  • Disabled nodes are not focusable or selectable.
  • ARIA labels and labelledby props are available for custom accessibility needs.

Best practices

  • Use controlled mode (signals + callbacks) for full synchronization with your app state.
  • Prefer unique value identifiers for each node.
  • Use icons to visually distinguish folders, files, or custom types.
  • Enable multi-select for batch operations; use checkboxes for independent selection.
  • Keep tree depth manageable for usability; collapse deeply nested nodes by default.
  • Ensure all labels are clear and concise for accessibility.
  • Use drag-and-drop only when reordering is required.

Released under the MIT License.