Tree

Tree is a component used to display hierarchical data structures in an expandable tree format.

  • pnpm-lock.yaml
  • package.json
  • tsconfig.json
  • README.md

Usage

import { Tree } from "@yamada-ui/react"
<Tree.Root>
  <Tree.Item>
    <Tree.Item />
  </Tree.Item>
  <Tree.Item />
</Tree.Root>

Use items

  • pnpm-lock.yaml
  • package.json
  • tsconfig.json
  • README.md

Change Variant

  • pnpm-lock.yaml
  • package.json
  • tsconfig.json
  • README.md
  • pnpm-lock.yaml
  • package.json
  • tsconfig.json
  • README.md

Change Size

  • src
  • pnpm-lock.yaml
  • package.json
  • tsconfig.json
  • README.md
  • src
  • pnpm-lock.yaml
  • package.json
  • tsconfig.json
  • README.md
  • src
  • pnpm-lock.yaml
  • package.json
  • tsconfig.json
  • README.md

Change Shape

  • pnpm-lock.yaml
  • package.json
  • tsconfig.json
  • README.md
  • pnpm-lock.yaml
  • package.json
  • tsconfig.json
  • README.md
  • pnpm-lock.yaml
  • package.json
  • tsconfig.json
  • README.md

Set Default Expanded Items

To have specific items expanded by default, set the item values to defaultExpandedValue.

  • src
    • components
      • tree.tsx
      • index.ts
  • pnpm-lock.yaml
  • package.json
  • tsconfig.json
  • README.md

Set Default Selected Item

To have a specific item selected by default, set the item value to defaultSelectedValue.

  • pnpm-lock.yaml
  • package.json
  • tsconfig.json
  • README.md

Select Multiple Items

To select multiple items, set multiple to true.

  • pnpm-lock.yaml
  • package.json
  • tsconfig.json
  • README.md

Enable Checkboxes

To enable checkboxes for items, set checkable to true.

  • pnpm-lock.yaml
  • package.json
  • tsconfig.json
  • README.md

Set Default Checked Items

To have specific items checked by default, set the item values to defaultCheckedValue.

  • pnpm-lock.yaml
  • package.json
  • tsconfig.json
  • README.md

Disable an Item

To disable a specific item, set disabled.

  • pnpm-lock.yaml
  • package.json
  • tsconfig.json
  • README.md

Show Guide Line

To show guide lines, set withGuideLine to true.

  • pnpm-lock.yaml
  • package.json
  • tsconfig.json
  • README.md

Hide Indicator

To hide the indicator, set indicatorHidden to true.

  • pnpm-lock.yaml
  • package.json
  • tsconfig.json
  • README.md

Add Animation

To add animation when expanding and collapsing, set animated to true.

  • pnpm-lock.yaml
  • package.json
  • tsconfig.json
  • README.md

Filtering

  • pnpm-lock.yaml
  • package.json
  • tsconfig.json
  • README.md

Async Loading

To load child items asynchronously, use asyncChildren instead of children.

  • pnpm-lock.yaml
  • package.json
  • tsconfig.json
  • README.md

Change Loading Scheme

  • pnpm-lock.yaml
  • package.json
  • tsconfig.json
  • README.md

Expand/Collapse All

To expand or collapse all items, use controlRef.

  • pnpm-lock.yaml
  • package.json
  • tsconfig.json
  • README.md

Customize Element

  • pnpm-lock.yaml
  • package.json
  • tsconfig.json
  • README.md
  • pnpm-lock.yaml
  • package.json
  • tsconfig.json
  • README.md

Customize Indicator

  • pnpm-lock.yaml
  • package.json
  • tsconfig.json
  • README.md

Control

  • node_modules
    • react
    • react-dom
  • pnpm-lock.yaml
  • package.json
  • tsconfig.json
  • README.md

Props

Accessibility

Tree follows the WAI-ARIA - TreeView Pattern for accessibility.

When aria-label is set, it will be read aloud by screen readers.

<Tree.Root aria-label="File tree" />

Keyboard Navigation

KeyDescriptionState
TabFocuses on the selected item or the first item.-
ArrowUpFocuses the previous enabled item.-
Shift + ArrowUpFocuses the previous enabled item and selects it.multiple={true}
Control + Shift + ArrowUpCollapses all items.-
ArrowDownFocuses the next enabled item.-
Shift + ArrowDownFocuses the next enabled item and selects it.multiple={true}
Control + Shift + ArrowDownExpands all items.-
ArrowRightIf the focused item is collapsed, expands it. If expanded, focuses the first child item.-
ArrowLeftIf the focused item is expanded, collapses it. If collapsed, focuses the parent item.-
Space, EnterSelects the focused item. If it's a group item, toggles its expansion/collapse.-
Shift + Space, EnterSelects all items between the first selected item and the currently focused item.multiple={true}
HomeFocuses the first enabled item.-
EndFocuses the last enabled item.-
Control + ASelects all enabled items.multiple={true}
a-z, A-ZFocuses expanded item whose label starts with the typed character(s).-

ARIA Roles and Attributes

ComponentRole and AttributesUsage
Tree.Rootrole="tree"Indicates that the element is a tree.
aria-multiselectableSet to "true" when multiple={true} or checkable={true}.
Tree.Itemrole="treeitem"Indicates that the element is a tree item.
aria-expandedSet to "true" when the item is expanded, "false" when collapsed.
aria-selectedSet to "true" when the item is selected.
aria-disabledSet to "true" when the item is disabled.
aria-levelSets the hierarchy level of the item.
aria-labelledbySets the id of the related Tree.Item > div > span.
Tree.Item > ulrole="group"Indicates that the element is a group.
aria-labelledbySets the id of the related Tree.Item > div > span.
aria-busySet to "true" when the item's children are loading.
Tree.Item > div > inputidUsed to associate with the parent Tree.Item > div > input.
aria-controlsSets the id of related child Tree.Item > div > input elements.
aria-labelledbySets the id of the related Tree.Item > div > span.
Tree.Item > div > spanidUsed to associate Tree.Item, Tree.Item > ul, and Tree.Item > div > input.

Similar Components

DataList

DataList is used to display a list of data items.

List

List is a component for displaying lists. By default, it renders a ul element.

NativeAccordion

NativeAccordion is a component for a list that displays information in an expandable or collapsible manner using the HTML details element.

Accordion

Accordion is a component for a list that displays information in an expandable or collapsible manner.

Timeline

Timeline is a component that is used to display a list of events in chronological order.

Tabs

Tabs is a component for switching between different display areas.

NativeTable

NativeTable is a component for efficiently organizing and displaying data.

Sidebar

Sidebar is a component used to display a list of items in a sidebar.

Uses Components & Hooks