ant-design/components/tree-select/index.zh-CN.md
二货爱吃白萝卜 cbcfd38ca7
docs: v5 site upgrade (#38328)
* build: try to use dumi as doc tool

* docs: migrate demo structure to dumi way

* refactor: use type export & import

* docs: migrate demo previewer to dumi

* docs: create empty layout & components

* docs: apply custom rehype plugin

* docs: create empty extra pages

* docs: Add Banner component

* chore: move theme tsconfig.json

* docs: home page init

* docs: migrate header (#37896)

* docs: header

* docs: update

* docs: home init

* clean up

* test: fix site lint

* chore: tsc ignore demo

* chore: dumi demo migrate script

* chore: cards

* docs: home layout

* docs: Update locale logic

* docs: fix getLink logic

* chore: fix ci (#37899)

* chore: fix ci

* ci: remove check-ts-demo

* ci: preview build

* test: ignore demo.tsx

* chore: update script

* test: update snapshot

* test: update node and image test

* chore: add .surgeignore

* docs: layout providers (#37908)

* docs: add components sidebar (#37923)

* docs: sidebar

* docs: update docs title

* docs: update design doc

* chore: code clean

* docs: handle changelog page

* docs: add title

* docs: add subtitle

* docs: active header nav

* chore: code clean

* docs: overview

* chore: code clean

* docs: update intl (#37918)

* docs: update intl

* chore: code clean

* docs: update favicons

* chore: update testPathIgnorePatterns

* chore: code clean

* chore: code clean

* chore: copy 404.html (#37996)

* docs: Home page theme picker

* chore: Update migrate script

* docs: home page update

* docs: theme editor style

* docs: theme lang

* chore: update migrate.js

* docs: fix demo (#38094)

* chore: update migrate.js

* docs: update md

* docs: update demo

* test: fix snapshot

* chore: move debug to code attr in migrate script

* chore: update md

Co-authored-by: PeachScript <scdzwyxst@gmail.com>

* feat: overview page

* feat: Migrate `404` page (#38118)

* feat: migrate IconSearch component (#37916)

* feat<site/IconSearch>: copy IconDisplay from site to .dumi

* feat<site/IconSearch>: change docs of icon

* feat<site/IconSearch>: tweak

* feat<site/IconSearch>: use useIntl instead of injectIntl

* feat<site/IconSearch>: fix ts type error

* feat<site/IconSearch>: use intl.formatMessage to render text

* docs: Adjust home btn sizw

* docs: Update doc

* feat: v5 site overview page (#38131)

* feat: site

* fix: fix

* feat: v5 site overview page

* fix: fix path

* fix: fix

* fix: fix

* docs: fix margin logic

* feat: v5 site change-log page (#38137)

* feat: v5 site change-log page (#38162)

* docs: site redirect to home pag

* docs: theme picker

* docs: use react-intl from dumi (#38183)

* docs: Theme Picker

* docs: update dumi config

* docs: home back fix

* docs: picker colorful

* docs: locale of it

* docs: update components desc

* docs: site of links

* docs: update components list

* docs: update desc

* feat: Migrate `DemoWrapper` component (#38166)

* feat: Migrate `DemoWrapper` component

* feat: remove invalid comments and add comment for `key` prop

* docs: FloatButton pure panel

* chore: update demo

* chore: update dumi config

* Revert "chore: update demo"

This reverts commit 028265d3ba.

* chore: test logic adjust to support cnpm modules

* chore: add locale alias

* docs: /index to /

* docs: add locale redirect head script

* chore: adjust compact

* docs: fix missing token

* feat: compact switch

* chore: code clean

* docs: update home

* docs: fix radius token

* docs: hash of it

* chore: adjust home page

* docs: Add background map

* docs: site theme bac logic

* docs: avatar

* docs: update logo color

* docs: home banner

* docs: adjust tour size

* docs: purepanl update

* docs: transfooter

* docs: update banner gif

* docs: content (#38361)

* docs: title & EditButton

* docs: content

* chore: fix toc

* docs: resource page

* docs: transform resource data from hast

* docs: filename & Resource Card

* chore: enable prerender

* chore: remove less

* docs: toc style

* chore: fix lint

* docs: fix Layout page

* docs: fix CP page

* chore: update demos

* docs: workaround for export dynamic html

* chore: enable demo eslint

* docs: table style

* fix: header shadow

* chore: update snapshot

* fix: toc style

* docs: add title

* docs: Adjust site

* feat: helmet

* docs: site css

* fix: description

* feat: toc debug

* docs: update config-provider

* feat: use colorPanel

* fix: colorPanel value

* feat: anchor ink ball style

* feat: apply theme editor

* fix: code block style

* chore: update demo

* chore: fix lint

* chore: code clean

* chore: update snapshot

* feat: ts2js

* chore: description

* docs: site ready for ssr

includes:
- move client render logic to useEffect in site theme
- extract antd cssinjs to a single css file like bisheng
- workaround to support react@18 pipeableStream for emotion

* chore: bump testing lib

* docs: font size of title

* chore: remove react-sortable-hoc

* chore: update snapshot

* chore: update script

Co-authored-by: PeachScript <scdzwyxst@gmail.com>
Co-authored-by: MadCcc <1075746765@qq.com>
Co-authored-by: zqran <uuxnet@gmail.com>
Co-authored-by: TrickyPi <530257315@qq.com>
Co-authored-by: lijianan <574980606@qq.com>
2022-11-09 12:28:04 +08:00

8.2 KiB
Raw Blame History

category subtitle group title cover demo
Components 树选择 数据录入 TreeSelect https://gw.alipayobjects.com/zos/alicdn/Ax4DA0njr/TreeSelect.svg
cols
2

树型选择控件。

何时使用

类似 Select 的选择控件,可选择的数据结构是一个树形结构时,可以使用 TreeSelect例如公司层级、学科系统、分类目录等等。

代码演示

基本 多选 从数据直接生成 可勾选 异步加载 线性样式 弹出位置 自定义状态 后缀图标 _InternalPanelDoNotUseOrYouWillBeFired

API

Tree props

参数 说明 类型 默认值 版本
allowClear 显示清除按钮 boolean false
autoClearSearchValue 当多选模式下值被选择,自动清空搜索框 boolean true
bordered 是否显示边框 boolean true
defaultValue 指定默认选中的条目 string | string[] -
disabled 是否禁用 boolean false
popupClassName 下拉菜单的 className 属性 string - 4.23.0
dropdownMatchSelectWidth 下拉菜单和选择器同宽。默认将设置 min-width当值小于选择框宽度时会被忽略。false 时会关闭虚拟滚动 boolean | number true
dropdownRender 自定义下拉框内容 (originNode: ReactNode, props) => ReactNode -
dropdownStyle 下拉菜单的样式 object -
fieldNames 自定义节点 label、value、children 的字段 object { label: label, value: value, children: children } 4.17.0
filterTreeNode 是否根据输入项进行筛选,默认用 treeNodeFilterProp 的值作为要筛选的 TreeNode 的属性值 boolean | function(inputValue: string, treeNode: TreeNode) (函数需要返回 bool 值) function
getPopupContainer 菜单渲染父节点。默认渲染到 body 上,如果你遇到菜单滚动定位问题,试试修改为滚动的区域,并相对其定位。示例 function(triggerNode) () => document.body
labelInValue 是否把每个选项的 label 包装到 value 中,会把 value 类型从 string 变为 {value: string, label: ReactNode, halfChecked(treeCheckStrictly 时有效): string[] } 的格式 boolean false
listHeight 设置弹窗滚动高度 number 256
loadData 异步加载数据 function(node) -
maxTagCount 最多显示多少个 tag响应式模式会对性能产生损耗 number | responsive - responsive: 4.10
maxTagPlaceholder 隐藏 tag 时显示的内容 ReactNode | function(omittedValues) -
multiple 支持多选(当设置 treeCheckable 时自动变为 true boolean false
notFoundContent 当下拉列表为空时显示的内容 ReactNode Not Found
placeholder 选择框默认文字 string -
placement 选择框弹出的位置 bottomLeft bottomRight topLeft topRight bottomLeft
searchValue 搜索框的值,可以通过 onSearch 获取用户输入 string -
showArrow 是否显示 suffixIcon,单选模式下默认 true boolean -
showCheckedStrategy 配置 treeCheckable 时,定义选中项回填的方式。TreeSelect.SHOW_ALL: 显示所有选中节点(包括父节点)。TreeSelect.SHOW_PARENT: 只显示父节点(当父节点下所有子节点都选中时)。 默认只显示子节点 TreeSelect.SHOW_ALL | TreeSelect.SHOW_PARENT | TreeSelect.SHOW_CHILD TreeSelect.SHOW_CHILD
showSearch 是否支持搜索框 boolean 单选false | 多选true
size 选择框大小 large | middle | small -
status 设置校验状态 'error' | 'warning' - 4.19.0
suffixIcon 自定义的选择框后缀图标, 多选模式下必须同时设置 showArrow 为 true ReactNode -
switcherIcon 自定义树节点的展开/折叠图标 ReactNode | ((props: AntTreeNodeProps) => ReactNode) - renderProps: 4.20.0
tagRender 自定义 tag 内容,多选时生效 (props) => ReactNode -
treeCheckable 显示 Checkbox boolean false
treeCheckStrictly checkable 状态下节点选择完全受控(父子节点选中状态不再关联),会使得 labelInValue 强制为 true boolean false
treeData treeNodes 数据,如果设置则不需要手动构造 TreeNode 节点value 在整个树范围内唯一) array<{value, title, children, [disabled, disableCheckbox, selectable, checkable]}> []
treeDataSimpleMode 使用简单格式的 treeData具体设置参考可设置的类型 (此时 treeData 应变为这样的数据结构: [{id:1, pId:0, value:'1', title:"test1",...},...] pId 是父节点的 id) boolean | object<{ id: string, pId: string, rootPId: string }> false
treeDefaultExpandAll 默认展开所有树节点 boolean false
treeDefaultExpandedKeys 默认展开的树节点 string[] -
treeExpandAction 点击节点 title 时的展开逻辑可选false | click | doubleClick string | boolean false 4.21.0
treeExpandedKeys 设置展开的树节点 string[] -
treeIcon 是否展示 TreeNode title 前的图标,没有默认样式,如设置为 true需要自行定义图标相关样式 boolean false
treeLine 是否展示线条样式,请参考 Tree - showLine boolean | object false 4.17.0
treeLoadedKeys (受控)已经加载的节点,需要配合 loadData 使用 string[] []
treeNodeFilterProp 输入项过滤对应的 treeNode 属性 string value
treeNodeLabelProp 作为显示的 prop 设置 string title
value 指定当前选中的条目 string | string[] -
virtual 设置 false 时关闭虚拟滚动 boolean true 4.1.0
onChange 选中树节点时调用此函数 function(value, label, extra) -
onDropdownVisibleChange 展开下拉菜单的回调 function(open) -
onSearch 文本框值变化时回调 function(value: string) -
onSelect 被选中时调用 function(value, node, extra) -
onTreeExpand 展示节点时调用 function(expandedKeys) -

Tree 方法

名称 描述 版本
blur() 移除焦点
focus() 获取焦点

TreeNode props

建议使用 treeData 来代替 TreeNode免去手工构造麻烦

参数 说明 类型 默认值 版本
checkable 当树为 Checkbox 时,设置独立节点是否展示 Checkbox boolean -
disableCheckbox 禁掉 Checkbox boolean false
disabled 是否禁用 boolean false
isLeaf 是否是叶子节点 boolean false
key 此项必须设置(其值在整个树范围内唯一) string -
selectable 是否可选 boolean true
title 树节点显示的内容 ReactNode ---
value 默认根据此属性值进行筛选(其值在整个树范围内唯一) string -

FAQ

onChange 时如何获得父节点信息?

从性能角度考虑,我们默认不透出父节点信息。你可以这样获得:https://codesandbox.io/s/wk080nn81k

自定义 Option 样式导致滚动异常怎么办?

请参考 Select 的 FAQ