Skip to main content
PROYECTOVIVIANA

Tree

Tree displays hierarchical data in an expandable and collapsible structure. It supports keyboard navigation, selection, and accessible tree patterns for file browsers, org charts, and nested data.

Import

import { Tree, TreeItem } from '@proyecto-viviana/solid-spectrum';

Basic Tree View

A file system tree with expand/collapse functionality. Click the arrow icons to expand or collapse folders.

src
components
Button.tsx
Dialog.tsx
Menu.tsx
index.ts
package.json
tsconfig.json
<Tree
  aria-label="File system"
  items={fileSystemData}
  expandedKeys={expandedKeys()}
  onExpandedChange={setExpandedKeys}
>
  {(item) => (
    <TreeItem id={item.key!} textValue={item.textValue}>
      {item.value!.name}
    </TreeItem>
  )}
</Tree>

With Selection

Enable selection mode to allow users to select tree items. Selected items are tracked and displayed below the tree.

CEO - Maria Garcia
CTO - James Chen
Frontend Lead - Anna Lee
Backend Lead - Omar Hassan
Infra Lead - Kenji Tanaka
CFO - Sarah Miller
Accounting - David Park
Finance - Lisa Wong
CMO - Robert Taylor
Marketing - Emily Davis
Sales - Michael Brown

Selected: None

<Tree
  aria-label="Organization chart"
  items={orgChartData}
  selectionMode="multiple"
  selectedKeys={selectedKeys()}
  onSelectionChange={setSelectedKeys}
>
  {(item) => (
    <TreeItem id={item.key!} textValue={item.textValue}>
      {item.value!.name}
    </TreeItem>
  )}
</Tree>

Tree Props

Props

PropTypeDefaultDescription
itemsT[]The data items rendered as tree nodes
selectionMode'none' | 'single' | 'multiple''none'How tree items can be selected
selectedKeysSet<Key> | 'all'Currently selected item keys (controlled)
onSelectionChange(keys: Set<Key> | 'all') => voidHandler called when selection changes
expandedKeysSet<Key>Currently expanded item keys (controlled)
onExpandedChange(keys: Set<Key>) => voidHandler called when expanded state changes
defaultExpandedKeysSet<Key>Default expanded keys (uncontrolled)
aria-labelstringAccessible label for the tree

TreeItem Props

Props

PropTypeDefaultDescription
idstringUnique identifier for the tree item
textValuestringText value for typeahead and accessibility
childrenJSX.Element | ((renderProps) => JSX.Element)Content of the tree item, or a render function for custom content
icon() => JSX.ElementOptional icon to display before the content
descriptionstringOptional description text below the label

Accessibility

  • Uses role="tree" and role="treeitem" ARIA patterns
  • Arrow keys navigate between visible tree items
  • Left arrow collapses an expanded node or moves to parent
  • Right arrow expands a collapsed node or moves to first child
  • Home/End keys jump to first/last visible item
  • Type-ahead search to quickly find items by text
  • aria-expanded state is announced for expandable items
  • Selection state is communicated via aria-selected
  • Nested level is exposed via aria-level