1 | # rc-tree-select
|
2 | ---
|
3 |
|
4 | React TreeSelect Component
|
5 |
|
6 | [![NPM version][npm-image]][npm-url]
|
7 | [![build status][travis-image]][travis-url]
|
8 | [![Test coverage][codecov-image]][codecov-url]
|
9 | [![gemnasium deps][gemnasium-image]][gemnasium-url]
|
10 | [![npm download][download-image]][download-url]
|
11 |
|
12 | [npm-image]: http://img.shields.io/npm/v/rc-tree-select.svg?style=flat-square
|
13 | [npm-url]: http://npmjs.org/package/rc-tree-select
|
14 | [travis-image]: https://img.shields.io/travis/react-component/tree-select.svg?style=flat-square
|
15 | [travis-url]: https://travis-ci.org/react-component/tree-select
|
16 | [codecov-image]: https://img.shields.io/codecov/c/github/react-component/tree-select/master.svg?style=flat-square
|
17 | [codecov-url]: https://codecov.io/gh/react-component/tree-select/branch/master
|
18 | [gemnasium-image]: http://img.shields.io/gemnasium/react-component/tree-select.svg?style=flat-square
|
19 | [gemnasium-url]: https://gemnasium.com/react-component/tree-select
|
20 | [node-image]: https://img.shields.io/badge/node.js-%3E=_0.10-green.svg?style=flat-square
|
21 | [node-url]: http://nodejs.org/download/
|
22 | [download-image]: https://img.shields.io/npm/dm/rc-tree-select.svg?style=flat-square
|
23 | [download-url]: https://npmjs.org/package/rc-tree-select
|
24 |
|
25 |
|
26 | ## Screenshots
|
27 |
|
28 | <img src="https://os.alipayobjects.com/rmsportal/HUhyhmpWyiGKnZF.png" width="288"/>
|
29 |
|
30 |
|
31 | ## Development
|
32 |
|
33 | ```
|
34 | npm install
|
35 | npm start
|
36 | ```
|
37 |
|
38 | ## Example
|
39 |
|
40 | http://localhost:8000/examples/
|
41 |
|
42 | online example: http://react-component.github.io/tree-select/
|
43 |
|
44 | ## install
|
45 |
|
46 | [![rc-tree-select](https://nodei.co/npm/rc-tree-select.png)](https://npmjs.org/package/rc-tree-select)
|
47 |
|
48 | ## API
|
49 |
|
50 | ### TreeSelect props
|
51 |
|
52 | | name | description | type | default |
|
53 | |----------|----------------|----------|--------------|
|
54 | |className | additional css class of root dom node | String | '' |
|
55 | |prefixCls | prefix class | String | '' |
|
56 | |animation | dropdown animation name. only support slide-up now | String | '' |
|
57 | |transitionName | dropdown css animation name | String | '' |
|
58 | |choiceTransitionName | css animation name for selected items at multiple mode | String | '' |
|
59 | |dropdownMatchSelectWidth | whether dropdown's with is same with select. Default set `min-width` same as input | bool | - |
|
60 | |dropdownClassName | additional className applied to dropdown | String | - |
|
61 | |dropdownStyle | additional style applied to dropdown | Object | {} |
|
62 | |dropdownPopupAlign | specify alignment for dropdown (alignConfig of [dom-align](https://github.com/yiminghe/dom-align)) | Object | - |
|
63 | |onDropdownVisibleChange | control dropdown visible | function | `() => { return true; }` |
|
64 | |notFoundContent | specify content to show when no result matches. | String | 'Not Found' |
|
65 | |showSearch | whether show search input in single mode | bool | true |
|
66 | |allowClear | whether allowClear | bool | false |
|
67 | |maxTagTextLength | max tag text length to show | number | - |
|
68 | |maxTagCount | max tag count to show | number | - |
|
69 | |maxTagPlaceholder | placeholder for omitted values | ReactNode/function(omittedValues) | - |
|
70 | |multiple | whether multiple select (true when enable treeCheckable) | bool | false |
|
71 | |disabled | whether disabled select | bool | false |
|
72 | |searchValue | work with `onSearch` to make search value controlled. | string | '' |
|
73 | |defaultValue | initial selected treeNode(s) | same as value type | - |
|
74 | |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}>. | - |
|
75 | |labelInValue| whether to embed label in value, see above value type | Bool | false |
|
76 | |onChange | called when select treeNode or input value change | function(value, label(null), extra) | - |
|
77 | |onSelect | called when select treeNode | function(value, node, extra) | - |
|
78 | |onSearch | called when input changed | function | - |
|
79 | |onTreeExpand | called when tree node expand | function(expandedKeys) | - |
|
80 | |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 |
|
81 | |treeIcon | show tree icon | bool | false |
|
82 | |treeLine | show tree line | bool | false |
|
83 | |treeDefaultExpandAll | default expand all treeNode | bool | false |
|
84 | |treeDefaultExpandedKeys | default expanded treeNode keys | Array<String> | - |
|
85 | |treeExpandedKeys | set tree expanded keys | Array<String> | - |
|
86 | |treeCheckable | whether tree show checkbox (select callback will not fire) | bool | false |
|
87 | |treeCheckStrictly | check node precisely, parent and children nodes are not associated| bool | false |
|
88 | |filterTreeNode | whether filter treeNodes by input value. default filter by treeNode's treeNodeFilterProp prop's value | bool/Function(inputValue:string, treeNode:TreeNode) | Function |
|
89 | |treeNodeFilterProp | which prop value of treeNode will be used for filter if filterTreeNode return true | String | 'value' |
|
90 | |treeNodeLabelProp | which prop value of treeNode will render as content of select | String | 'title' |
|
91 | |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]}> | [] |
|
92 | |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 |
|
93 | |loadData | load data asynchronously | function(node) | - |
|
94 | |getPopupContainer | container which popup select menu rendered into | function(trigger:Node):Node | function(){return document.body;} |
|
95 | |autoClearSearchValue | auto clear search input value when multiple select is selected/deselected | boolean | true |
|
96 | | inputIcon | specify the select arrow icon | ReactNode \| (props: TreeProps) => ReactNode | - |
|
97 | | clearIcon | specify the clear icon | ReactNode \| (props: TreeProps) => ReactNode | - |
|
98 | | removeIcon | specify the remove icon | ReactNode \| (props: TreeProps) => ReactNode | - |
|
99 | |switcherIcon| specify the switcher icon | ReactNode \| (props: TreeProps) => ReactNode | - |
|
100 | |virtual| Disable virtual when `false` | false | - |
|
101 |
|
102 |
|
103 | ### TreeNode props
|
104 | > note: you'd better to use `treeData` instead of using TreeNode.
|
105 |
|
106 | | name | description | type | default |
|
107 | |----------|----------------|----------|--------------|
|
108 | |disabled | disable treeNode | bool | false |
|
109 | |key | it's value must be unique across the tree's all TreeNode, you must set it | String | - |
|
110 | |value | default as treeNodeFilterProp (be unique across the tree's all TreeNode) | String | '' |
|
111 | |title | tree/subTree's title | String/element | '---' |
|
112 | |isLeaf | whether it's leaf node | bool | false |
|
113 |
|
114 |
|
115 | ## note
|
116 | 1. Optimization tips(when there are large amounts of data, like more than 5000 nodes)
|
117 | - Do not Expand all nodes.
|
118 | - Recommend not exist many `TreeSelect` components in a page at the same time.
|
119 | - Recommend not use `treeCheckable` mode, or use `treeCheckStrictly`.
|
120 | 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`方法、但它们的参数(第三个参数)是不同的。)
|
121 |
|
122 | ## Test Case
|
123 |
|
124 | http://localhost:8000/tests/runner.html?coverage
|
125 |
|
126 | ## Coverage
|
127 |
|
128 | http://localhost:8000/node_modules/rc-server/node_modules/node-jscover/lib/front-end/jscoverage.html?w=http://localhost:8000/tests/runner.html?coverage
|
129 |
|
130 | ## License
|
131 |
|
132 | rc-tree-select is released under the MIT license.
|