Skip to content
Alea0.1

Data display

Tree

Nested items that expand and collapse: files, categories, outlines.

Ant Design: Tree

import { Tree, TreeItem } from '@alea/ui';

Examples

Tree

Folders that open and close.

src
index.ts
tokens.css

Selection

Pick several files; Space selects, arrows move.

tokens
colors.json
type.json
space.json

Props

Tree props

Nested items that expand and collapse: files, categories, outlines. Arrow right opens, left closes.

PropTypeDefaultDescription
aria-labelstring-Defines a string value that labels the current element. (React Aria)
autoFocusboolean | FocusStrategy-Whether to auto focus the gridlist or an option. (React Aria)
childrenReactNode | ((item: T) => ReactNode)-The contents of the collection. (React Aria)
classNameClassNameOrFunction<TreeRenderProps>-The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. A function may be provided to compute the class based on component state. (React Aria)
defaultExpandedKeysIterable<Key>-The initial expanded keys in the collection (uncontrolled). (React Aria)
defaultSelectedKeysIterable<Key> | "all"-The initial selected keys in the collection (uncontrolled). (React Aria)
disabledKeysIterable<Key>-The item keys that are disabled. These items cannot be selected, focused, or otherwise interacted with. (React Aria)
expandedKeysIterable<Key>-The currently expanded keys in the collection (controlled). (React Aria)
idstring-The element's unique identifier. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id). (React Aria)
onExpandedChange((keys: Set<Key>) => any)-Handler that is called when items are expanded or collapsed. (React Aria)
onSelectionChange((keys: Selection) => void)-Handler that is called when the selection changes. (React Aria)
selectedKeysIterable<Key> | "all"-The currently selected keys in the collection (controlled). (React Aria)
selectionMode"single" | "multiple" | "none"-The type of selection that is allowed in the collection. (React Aria)
styleStyleOrFunction<DisclosureGroupRenderProps>-The inline [style](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) for the element. A function may be provided to compute the style based on component state. (React Aria)

TreeItem props

An item in a Tree; nest TreeItems inside for children.

PropTypeDefaultDescription
titlerequiredReactNode-The item's label.
childrenReactNode-Nested TreeItems.
iconReactNode-An icon before the title.
textValuestring-Text for typeahead and screen readers when title is not plain text.

Accessibility

  • A treegrid; expanded state is announced.

Keyboard

KeyDoes
Arrow RightExpands or moves to the first child
Arrow LeftCollapses or moves to the parent
Arrow Up / DownMove

Do and don't

Do

  • Give each item a textValue so typeahead works.
  • Keep trees shallow: three or four levels.

Don't

  • Don't use a tree for flat lists.
  • Don't load thousands of nodes at once: load children when expanded.
Tested with axe, keyboard and screen reader roles