1 | # rc-tree-select
|
2 |
|
3 | React TreeSelect Component
|
4 |
|
5 | [![NPM version][npm-image]][npm-url] [![dumi](https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square)](https://github.com/umijs/dumi) [![build status][github-actions-image]][github-actions-url] [![Test coverage][coveralls-image]][coveralls-url] [![Dependencies][david-image]][david-url] [![DevDependencies][david-dev-image]][david-dev-url] [![npm download][download-image]][download-url] [![bundle size][bundlephobia-image]][bundlephobia-url]
|
6 |
|
7 | [npm-image]: http://img.shields.io/npm/v/rc-tree-select.svg?style=flat-square
|
8 | [npm-url]: http://npmjs.org/package/rc-tree-select
|
9 | [github-actions-image]: https://github.com/react-component/tree-select/workflows/CI/badge.svg
|
10 | [github-actions-url]: https://github.com/react-component/tree-select/actions
|
11 | [circleci-image]: https://img.shields.io/circleci/react-component/tree-select/master?style=flat-square
|
12 | [circleci-url]: https://circleci.com/gh/react-component/tree-select
|
13 | [coveralls-image]: https://img.shields.io/coveralls/react-component/tree-select.svg?style=flat-square
|
14 | [coveralls-url]: https://coveralls.io/r/react-component/tree-select?branch=master
|
15 | [david-url]: https://david-dm.org/react-component/tree-select
|
16 | [david-image]: https://david-dm.org/react-component/tree-select/status.svg?style=flat-square
|
17 | [david-dev-url]: https://david-dm.org/react-component/tree-select?type=dev
|
18 | [david-dev-image]: https://david-dm.org/react-component/tree-select/dev-status.svg?style=flat-square
|
19 | [download-image]: https://img.shields.io/npm/dm/rc-tree-select.svg?style=flat-square
|
20 | [download-url]: https://npmjs.org/package/rc-tree-select
|
21 | [bundlephobia-url]: https://bundlephobia.com/result?p=rc-tree-select
|
22 | [bundlephobia-image]: https://badgen.net/bundlephobia/minzip/rc-tree-select
|
23 |
|
24 | ## Screenshots
|
25 |
|
26 | <img src="https://os.alipayobjects.com/rmsportal/HUhyhmpWyiGKnZF.png" width="288"/>
|
27 |
|
28 |
|
29 | ## Development
|
30 |
|
31 | ```
|
32 | npm install
|
33 | npm start
|
34 | ```
|
35 |
|
36 | ## Example
|
37 |
|
38 | http://localhost:8000/examples/
|
39 |
|
40 | online example: https://tree-select-react-component.vercel.app/
|
41 |
|
42 | ## install
|
43 |
|
44 | [![rc-tree-select](https://nodei.co/npm/rc-tree-select.png)](https://npmjs.org/package/rc-tree-select)
|
45 |
|
46 | ## API
|
47 |
|
48 | ### TreeSelect props
|
49 |
|
50 | | name | description | type | default |
|
51 | |----------|----------------|----------|--------------|
|
52 | |className | additional css class of root dom node | String | '' |
|
53 | |prefixCls | prefix class | String | '' |
|
54 | |animation | dropdown animation name. only support slide-up now | String | '' |
|
55 | |transitionName | dropdown css animation name | String | '' |
|
56 | |choiceTransitionName | css animation name for selected items at multiple mode | String | '' |
|
57 | |dropdownMatchSelectWidth | whether dropdown's with is same with select. Default set `min-width` same as input | bool | - |
|
58 | |dropdownClassName | additional className applied to dropdown | String | - |
|
59 | |dropdownStyle | additional style applied to dropdown | Object | {} |
|
60 | |dropdownPopupAlign | specify alignment for dropdown (alignConfig of [dom-align](https://github.com/yiminghe/dom-align)) | Object | - |
|
61 | |onDropdownVisibleChange | control dropdown visible | function | `() => { return true; }` |
|
62 | |notFoundContent | specify content to show when no result matches. | String | 'Not Found' |
|
63 | |showSearch | whether show search input in single mode | bool | true |
|
64 | |allowClear | whether allowClear | bool | false |
|
65 | |maxTagTextLength | max tag text length to show | number | - |
|
66 | |maxTagCount | max tag count to show | number | - |
|
67 | |maxTagPlaceholder | placeholder for omitted values | ReactNode/function(omittedValues) | - |
|
68 | |multiple | whether multiple select (true when enable treeCheckable) | bool | false |
|
69 | |disabled | whether disabled select | bool | false |
|
70 | |searchValue | work with `onSearch` to make search value controlled. | string | '' |
|
71 | |defaultValue | initial selected treeNode(s) | same as value type | - |
|
72 | |value | current selected treeNode(s). | normal: String/Array<String>. labelInValue: {value:String,label:React.Node}/Array<{value,label}>. treeCheckStrictly(halfChecked default false): {value:String,label:React.Node, halfChecked}/Array<{value,label,halfChecked}>. | - |
|
73 | |labelInValue| whether to embed label in value, see above value type | Bool | false |
|
74 | |onChange | called when select treeNode or input value change | function(value, label(null), extra) | - |
|
75 | |onSelect | called when select treeNode | function(value, node, extra) | - |
|
76 | |onSearch | called when input changed | function | - |
|
77 | |onTreeExpand | called when tree node expand | function(expandedKeys) | - |
|
78 | |showCheckedStrategy | `TreeSelect.SHOW_ALL`: show all checked treeNodes (Include parent treeNode). `TreeSelect.SHOW_PARENT`: show checked treeNodes (Just show parent treeNode). Default just show child. | enum{TreeSelect.SHOW_ALL, TreeSelect.SHOW_PARENT, TreeSelect.SHOW_CHILD } | TreeSelect.SHOW_CHILD |
|
79 | |treeIcon | show tree icon | bool | false |
|
80 | |treeLine | show tree line | bool | false |
|
81 | |treeDefaultExpandAll | default expand all treeNode | bool | false |
|
82 | |treeDefaultExpandedKeys | default expanded treeNode keys | Array<String> | - |
|
83 | |treeExpandedKeys | set tree expanded keys | Array<String> | - |
|
84 | |treeCheckable | whether tree show checkbox (select callback will not fire) | bool | false |
|
85 | |treeCheckStrictly | check node precisely, parent and children nodes are not associated| bool | false |
|
86 | |filterTreeNode | whether filter treeNodes by input value. default filter by treeNode's treeNodeFilterProp prop's value | bool/Function(inputValue:string, treeNode:TreeNode) | Function |
|
87 | |treeNodeFilterProp | which prop value of treeNode will be used for filter if filterTreeNode return true | String | 'value' |
|
88 | |treeNodeLabelProp | which prop value of treeNode will render as content of select | String | 'title' |
|
89 | |treeData | treeNodes data Array, if set it then you need not to construct children TreeNode. (value should be unique across the whole array) | array<{value,label,children, [disabled,selectable]}> | [] |
|
90 | |treeDataSimpleMode | enable simple mode of treeData.(treeData should be like this: [{id:1, pId:0, value:'1', label:"test1",...},...], `pId` is parent node's id) | bool/object{id:'id', pId:'pId', rootPId:null} | false |
|
91 | |loadData | load data asynchronously | function(node) | - |
|
92 | |getPopupContainer | container which popup select menu rendered into | function(trigger:Node):Node | function(){return document.body;} |
|
93 | |autoClearSearchValue | auto clear search input value when multiple select is selected/deselected | boolean | true |
|
94 | | inputIcon | specify the select arrow icon | ReactNode \| (props: TreeProps) => ReactNode | - |
|
95 | | clearIcon | specify the clear icon | ReactNode \| (props: TreeProps) => ReactNode | - |
|
96 | | removeIcon | specify the remove icon | ReactNode \| (props: TreeProps) => ReactNode | - |
|
97 | |switcherIcon| specify the switcher icon | ReactNode \| (props: TreeProps) => ReactNode | - |
|
98 | |virtual| Disable virtual when `false` | false | - |
|
99 |
|
100 |
|
101 | ### TreeNode props
|
102 | > note: you'd better to use `treeData` instead of using TreeNode.
|
103 |
|
104 | | name | description | type | default |
|
105 | |----------|----------------|----------|--------------|
|
106 | |disabled | disable treeNode | bool | false |
|
107 | |key | it's value must be unique across the tree's all TreeNode, you must set it | String | - |
|
108 | |value | default as treeNodeFilterProp (be unique across the tree's all TreeNode) | String | '' |
|
109 | |title | tree/subTree's title | String/element | '---' |
|
110 | |isLeaf | whether it's leaf node | bool | false |
|
111 |
|
112 |
|
113 | ## note
|
114 | 1. Optimization tips(when there are large amounts of data, like more than 5000 nodes)
|
115 | - Do not Expand all nodes.
|
116 | - Recommend not exist many `TreeSelect` components in a page at the same time.
|
117 | - Recommend not use `treeCheckable` mode, or use `treeCheckStrictly`.
|
118 | 2. In `treeCheckable` mode, It has the same effect when click `x`(node in Selection box) or uncheck in the treeNode(in dropdown panel), but the essence is not the same. So, even if both of them trigger `onChange` method, but the parameters (the third parameter) are different. (中文:在`treeCheckable`模式下,已选择节点上的`x`删除操作、和相应 treeNode 节点上 checkbox 的 uncheck 操作,最终效果相同,但本质不一样。前者跟弹出的 tree 组件可以“毫无关系”(例如 dropdown 没展开过,tree 也就没渲染好),而后者是 tree 组件上的节点 uncheck 事件。所以、即便两者都会触发`onChange`方法、但它们的参数(第三个参数)是不同的。)
|
119 |
|
120 | ## Test Case
|
121 |
|
122 | http://localhost:8000/tests/runner.html?coverage
|
123 |
|
124 | ## Coverage
|
125 |
|
126 | http://localhost:8000/node_modules/rc-server/node_modules/node-jscover/lib/front-end/jscoverage.html?w=http://localhost:8000/tests/runner.html?coverage
|
127 |
|
128 | ## License
|
129 |
|
130 | rc-tree-select is released under the MIT license.
|