Component

Tree

安装 Installation

npx timkit add tree --yes --framework react

用法 Usage

import { Tree } from "@/components/ui/tree"

className 与 variant、size 可以一起用。字段以 timkit agent inspect tree --json 的 props 为准。

示例

Examples

一次看一个示例。左侧按名称筛选,预览里可切换源码和框架。

13 / 13

Tree · Interactive State · 01

Loading preview...

结构化 API

Structured API

与 UCS schema 对齐的 props、逻辑机与多框架运行时。

Component

tree

Logic

none

Runtime Frameworks

ReactVueWeappHTML

Supported Platforms

WebWeChat Mini Program

Configuration

PropTypeDefaultDescription
logic.provider*
enum (zag | native | none)
noneState and interaction provider used by this component.
logic.machine
string
-Underlying state machine identifier when provider is zag.
platforms*
array
Web, WeChat Mini ProgramPlatforms officially supported by this schema.
frameworks*
array
React, Vue, Weapp, HTMLFramework demos/code currently available in registry files.
dependencies
array
@headless-tree/core, @timui/coreRuntime package dependencies required by this registry item.
optionalPeerDependencies
array
lucide-reactOptional peer dependencies used by this registry item.
registryDependencies
array
-Dependent Timkit registry components/hook entries.

Props

PropTypeDefaultDescription
data
array
-The structured array of data used to render the component.
indent
number
20The indentation for children.
tree
object
-The node tree or hierarchical data structure.
disabled
boolean
falseWhen true, expanding and selecting are ignored.
selected
string
-The controlled id of the selected node.

Events

PropTypeDefaultDescription
onSelectedChange
event
-Event handler called with the next selected id. A controlled selected value stays until the parent applies it.

Slots

PropTypeDefaultDescription
default
slot
-The tree items

Parts

PropTypeDefaultDescription
root*
root
-The tree container
item
part
-A tree node
label
part
-A node label
dragLine
part
-The drag indicator
This API reference is generated from `/packages/core` component schemas to keep React/Vue/Weapp docs consistent.

该组件尚无扩展说明文档。

键盘与焦点

Keyboard

跨 React、Vue 与小程序共享的交互与可读名称约定。

  • Enter or Space selects a row.
  • ArrowDown and ArrowUp move between visible rows.
  • Home moves to the first visible row.
  • End moves to the last.
  • None of these keys changes the selection or opens a branch.
  • ArrowRight opens a closed branch or moves into it.
  • ArrowLeft closes an open branch or moves to its parent.
  • One row is in the tab order.
  • On the mini program, Enter or Space on the expand control opens or closes that branch, and Enter or Space on the row selects it.
  • In static HTML, only one row stays in the tab order.

行为契约

Contract

props、默认值和运行时状态。

  • A controlled selected id stays until the parent applies the next selected node.
  • Expanding a branch does not change the selection.
  • Child rows are indented by indent pixels.
  • The default indent is 20.
  • A letter moves to the next visible row whose label starts with that letter.
  • A disabled tree ignores that letter.
  • The selected row is visible as Node N of the visible row count.
  • A hidden selection or an empty value has no node status.
  • An omitted name is Tree.
  • A passed aria-label names the tree.
  • On the mini program, a row is named by its label. aria-labelledby suppresses that name.
  • The expand mark is hidden from the name on the mini program, in Vue, and on React.
  • In static HTML, child rows sit in a group.
  • Each row exposes whether it is selected.
  • On the mini program, aria-labelledby leaves aria-label off.
  • On the mini program, a disabled tree sets aria-disabled on each row.