Hulian UIv0.93.5413 components0 components
  • Start
  • Components
  • Blocks
  • Pages
  • Demos
  • Changelog
ChineseEnglish
  • ComponentsComponents
  • ThemeTheme

Collections

  • QuestionCard
  • Table
  • Book3D
  • ProTable
  • PricingTable
  • JsonViewer
  • EditableTable
  • List
  • Descriptions
  • RowActions
  • Tree
  • Card
  • Carousel
  • Video
  • Audio
  • BentoGrid
  • Image
  • MagicCard
  • AnimatedList
  • Marquee
  • Sortable
  • Kanban
  • DesignCanvas
  • LayerTree
  • StageDraw
  • SlideDeck
  • PresenterView
  • ComponentPicker
  • EventStream
  • QueueLane
  • DocumentSheet
  • Novel reader
  • Scheduler
  • Org classroom
  • Danmaku
  • LiveChat
  • LivePlayer
  • LogViewer
  • FileTree
  • CodeReviewThread
  • VirtualList
  • InfiniteScroll
  • LogoLoop
  • BounceCards
  • CardSwap
  • ChromaGrid
  • CircularGallery
  • DomeGallery
  • FlyingPosters
  • InfiniteMenu
  • MagicBento
  • ScrollStack
  • ProfileCard
  • TiltedCard
  • PixelCard
  • DecayCard
  • ReflectiveCard
  • Folder

Charts and Diagrams

  • Flow
  • Diagram
  • Paper
  • SequenceDiagram
  • Sankey
  • Sparkline
  • Funnel
  • Treemap
  • Gantt
  • Heatmap
  • ContributionGraph
  • Legend
  • Chart
  • WorldMap

Information

  • ImageViewer
  • LiveProductCard
  • DiffStat
  • ScoreRing
  • ScoreScale
  • Badge
  • Dot
  • StatusDot
  • Chip
  • FilterChip
  • Coupon
  • Tag
  • Annotation
  • Avatar
  • AvatarCircles
  • User
  • QRCode
  • Comment
  • RelativeTime
  • GitCommit
  • DeployStatus
  • ShieldBadge
  • AwardBadge
  • CreditCard
  • IconTile

Metrics

  • Stat
  • Statistic
  • Meter
  • Timeline
  • NumberTicker

Placeholders

  • Empty
  • Skeleton
  • Watermark

Tree

tree

Renders expandable hierarchical nodes with selection and keyboard navigation.

Usage

Basic usage

Radio highlight + arrow key navigation; defaultExpandedKeys controls the initial expansion of branches.

  • Design
    • Tokens
    • Theme
    • Animation
  • Components
    • Form
      • Input
      • Select
    • Feedback
      • Alert
      • Toast
  • Documentation
tsx
<Tree
  nodes={nodes}
  defaultExpandedKeys={["design", "components"]}
  defaultSelectedKeys={["theme"]}
/>

Check

checkable Turn on the parent-child cascade check, and half-select will automatically show indeterminate.

  • Design
    • Tokens
    • Theme
    • Animation
  • Components
    • Form
      • Input
      • Select
    • Feedback
      • Alert
      • Toast
  • Documentation
tsx
<Tree
  nodes={nodes}
  checkable
  defaultExpandedKeys={["design", "components", "form"]}
  defaultCheckedKeys={["tokens"]}
/>

Connecting cable

showLine displays hierarchical connection lines, making the structure hierarchy clearer.

  • Design
    • Tokens
    • Theme
    • Animation
  • Components
    • Form
      • Input
      • Select
    • Feedback
      • Alert
      • Toast
  • Documentation
tsx
<Tree nodes={nodes} showLine defaultExpandedKeys={["components", "form"]} />

Search within the tree

searchable provides a search box, where hit nodes are highlighted and ancestor paths are automatically expanded.

  • Design
    • Tokens
    • Theme
    • Animation
  • Components
    • Form
      • Input
      • Select
    • Feedback
      • Alert
      • Toast
  • Documentation
tsx
<Tree nodes={nodes} searchable searchPlaceholder="Search component" />

When to use

Use Tree for a file hierarchy, organization, category navigation, or permission selection. Use List for flat entries or JsonViewer for read-only JSON. Tree provides keyboard-complete WAI-ARIA behavior and cascading check state.

Import

ts
import { Tree, buildIndex, flattenVisible, getNodePath, toggleChecked, getCheckState, normalizeCheckedToLeaves, computeChecked, filterTree, nodeSearchText, canDropOn, isDescendant, resolveDropPosition, type FlatRow, type TreeIndex, type CheckState } from "@hulianui/ui"

Props

TreeProps:

NameTypeDefaultDescription
nodes*TreeNode[]-{ key, label, icon?, children?, disabled?, searchText? } hierarchy.
expandedKeysstring[]-Controlled expanded keys.
defaultExpandedKeysstring[]-Initial uncontrolled expanded keys.
selectablebooleantrueEnables single selection outside checkable mode.
selectedKeysstring[]-Controlled selected keys.
defaultSelectedKeysstring[]-Initial uncontrolled selected keys.
checkablebooleanfalseAdds cascading checkboxes.
checkedKeysstring[]-Controlled checked keys.
defaultCheckedKeysstring[]-Initial uncontrolled checked keys.
expandTrigger"row" | "icon""row"Row expands parents without selecting them; icon reserves row clicks for selection or checking.
draggablebooleanfalseEnables native HTML drag sorting only when onDrop is supplied.
allowDropInside(target: TreeNode) => booleanAlways trueControls whether a target accepts reparenting inside it.
virtualboolean | { height?, itemHeight?, overscan? }falseFlat virtual rendering, defaulting to height 320, itemHeight 36, and overscan 8.
showLinebooleanfalseShows connector lines; ignored by virtual rendering.
searchablebooleanfalseShows built-in tree search.
searchPlaceholderstringlocaleSearch input placeholder; an explicit value overrides the locale.
classNamestring-Root class name.
aria-labelstringlocaleAccessible tree label; an explicit value overrides the locale.

Events

EventTypeDescription
onExpandedChange(keys: string[]) => voidExpanded-key change.
onSelect(keys: string[], node: TreeNode) => voidSelection change.
onDrop(e: { dragKey, dropKey, position }) => voidReports before, after, or inside drop semantics.
onCheck(info: { checkedKeys: string[]; halfCheckedKeys: string[] }, node: TreeNode) => voidReports fully checked and half-checked keys separately.

Usage notes

  • Expansion, selection, and checking each independently follow controlled-or-uncontrolled symmetry. Pair a controlled key prop with its callback.
  • In checkable mode, half-checked parents are returned separately and never appear in checkedKeys.
  • Every node needs a stable key.
  • disabled prevents selection and checking but intentionally does not block expansion, preserving access to descendants.
  • With the default row expansion trigger, parents do not invoke onSelect. Choose expandTrigger="icon" when folders or categories must be selectable.
  • Dragging never mutates nodes. Apply the returned relative position yourself. Self drops, descendant cycles, and no-op inside drops are rejected.
  • Virtual mode removes nested transitions and connector lines. itemHeight must match real fixed row height; do not virtualize wrapping labels.
  • ReactNode labels need searchText; otherwise search and typeahead fall back to matching the key.
  • The default tree label, search placeholder, and empty-result message follow ConfigProvider (zhCN / enUS). Explicit aria-label and searchPlaceholder props win. Legacy custom locales without components.tree keep the Chinese fallback.

Related

Table · Book3D · ProTable · PricingTable · JsonViewer · EditableTable

Playground

  • Design
    • Tokens
    • Theme
    • Animation
  • Components
    • Form
      • Input
      • Select
    • Feedback
      • Alert
      • Toast
  • Documentation
<Tree
  nodes={nodes}
  defaultExpandedKeys={["design", "components"]}
/>
PreviousRowActionsData DisplayNextCard

On this page

  • Usage
  • Documentation
    • When to use
    • Import
    • Props
    • Events
    • Usage notes
    • Related
  • Playground