structyl

The full prop reference for the Tree component. A hierarchical list, like a file explorer.

Import

tsx
import { Tree } from '@structyl/styled';

Props

Tree.Root

Root component for the tree; manages expanded, selected, and focused states. Extends ul element.

PropTypeDefault
asChild#boolean

Replace element with first child and merge props

defaultExpanded#string[]

Initial expanded item IDs (uncontrolled)

[]
expanded#string[]

Controlled expanded item IDs

onExpandedChange#(expanded: string[]) => void

Callback when expanded items change

defaultSelected#string

Initial selected item ID (uncontrolled)

selected#string

Controlled selected item ID

onSelectedChange#(id: string | undefined) => void

Callback when selected item changes

className#string

CSS class names (styled adds 'text-sm' default)

ref#React.Ref<HTMLUListElement>

Forward ref to underlying ul element

Tree.Item

Container for a tree item. Extends li element. Must be a direct child of Root or Group.

PropTypeDefault
id#string

Unique identifier for the tree item (required)

asChild#boolean

Replace element with first child and merge props

hasChildren#boolean

Whether this item has child items (shows expand chevron)

false
level#number

Nesting level for accessibility (aria-level)

1
className#string

CSS class names

ref#React.Ref<HTMLLIElement>

Forward ref to underlying li element

Tree.Trigger

Clickable trigger for item expansion and selection. Extends div element.

PropTypeDefault
hasChildren#boolean

When false, hides the expand chevron icon (styled only)

className#string

CSS class names (styled adds default styles for layout, hover, focus ring)

onClick#(event: React.MouseEvent<HTMLDivElement>) => void

Native click handler (composed with selection/expansion logic)

onFocus#(event: React.FocusEvent<HTMLDivElement>) => void

Native focus handler (composed with focus tracking)

onKeyDown#(event: React.KeyboardEvent<HTMLDivElement>) => void

Native keydown handler (composed with keyboard navigation: Arrow Right/Left for expand/collapse, Enter/Space for select)

ref#React.Ref<HTMLDivElement>

Forward ref to underlying div element

Tree.Group

Container for child tree items. Only renders when parent item is expanded. Extends ul element.

PropTypeDefault
className#string

CSS class names (styled adds left border and left padding)

ref#React.Ref<HTMLUListElement>

Forward ref to underlying ul element

Source code

If you didn't find what you need here, read the component implementation .

structyl — Accessible React Component Library