Skip to content

Commit af361f7

Browse files
committed
fix: tree and tree-select support number key #343
1 parent 14b8d67 commit af361f7

File tree

13 files changed

+113
-103
lines changed

13 files changed

+113
-103
lines changed

components/tree-select/index.en-US.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
| dropdownMatchSelectWidth | Determine whether the dropdown menu and the select input are the same width | boolean | true |
1313
| dropdownStyle | To set the style of the dropdown menu | object | - |
1414
| filterTreeNode | Whether to filter treeNodes by input value. The value of `treeNodeFilterProp` is used for filtering by default. | boolean\|Function(inputValue: string, treeNode: TreeNode) (should return boolean) | Function |
15-
| getPopupContainer | To set the container of the dropdown menu. The default is to create a `div` element in `body`, you can reset it to the scrolling area and make a relative reposition. [example](https://codepen.io/afc163/pen/zEjNOy?editors=0010) | Function(triggerNode) | () => document.body |
15+
| getPopupContainer | To set the container of the dropdown menu. The default is to create a `div` element in `body`, you can reset it to the scrolling area and make a relative reposition. | Function(triggerNode) | () => document.body |
1616
| labelInValue | whether to embed label in value, turn the format of value from `string` to `{value: string, label: VNode, halfChecked: string[]}` | boolean | false |
1717
| loadData | Load data asynchronously. | function(node) | - |
1818
| multiple | Support multiple or not, will be `true` when enable `treeCheckable`. | boolean | false |
@@ -27,8 +27,8 @@
2727
| treeData | Data of the treeNodes, manual construction work is no longer needed if this property has been set(ensure the Uniqueness of each value) | array<{ value, label, children, [disabled, disableCheckbox, selectable] }> | \[] |
2828
| treeDataSimpleMode | Enable simple mode of treeData.(treeData should like this: [{id:1, pId:0, value:'1', label:"test1",...},...], pId is parent node's id) | false\|Array<{ id: string, pId: string, rootPId: null }> | false |
2929
| treeDefaultExpandAll | Whether to expand all treeNodes by default | boolean | false |
30-
| treeDefaultExpandedKeys | Default expanded treeNodes | string\[] | - |
31-
| treeExpandedKeys | Set expanded keys | string\[] | - |
30+
| treeDefaultExpandedKeys | Default expanded treeNodes | string\[] \| number\[] | - |
31+
| treeExpandedKeys | Set expanded keys | string\[] \| number\[] | - |
3232
| treeNodeFilterProp | Will be used for filtering if `filterTreeNode` returns true | string | 'value' |
3333
| treeNodeLabelProp | Will render as content of select | string | 'title' |
3434
| value(v-model) | To set the current selected treeNode(s). | string\|string\[] | - |
@@ -58,7 +58,7 @@
5858
| disableCheckbox | Disables the checkbox of the treeNode | boolean | false |
5959
| disabled | Disabled or not | boolean | false |
6060
| isLeaf | Leaf node or not | boolean | false |
61-
| key | Required property, should be unique in the tree | string | - |
61+
| key | Required property, should be unique in the tree | string \| number | - |
6262
| title | Content showed on the treeNodes | string\|slot | '---' |
6363
| value | Will be treated as `treeNodeFilterProp` by default, should be unique in the tree | string | - |
6464
| scopedSlots | When using treeNodes, you can use this property to configure the properties that support the slot, such as `scopedSlots: { title: 'XXX'}` | object | - |

components/tree-select/index.zh-CN.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
| treeData | treeNodes 数据,如果设置则不需要手动构造 TreeNode 节点(value 在整个树范围内唯一) | array<{value, label, children, [disabled, disableCheckbox, selectable]}> | \[] |
2828
| treeDataSimpleMode | 使用简单格式的 treeData,具体设置参考可设置的类型 (此时 treeData 应变为这样的数据结构: [{id:1, pId:0, value:'1', label:"test1",...},...], `pId` 是父节点的 id) | false\|Array<{ id: string, pId: string, rootPId: null }> | false |
2929
| treeDefaultExpandAll | 默认展开所有树节点 | boolean | false |
30-
| treeDefaultExpandedKeys | 默认展开的树节点 | string\[] | - |
31-
| treeExpandedKeys | 设置展开的树节点 | string\[] | - |
30+
| treeDefaultExpandedKeys | 默认展开的树节点 | string\[] \| number\[] | - |
31+
| treeExpandedKeys | 设置展开的树节点 | string\[] \| number\[] | - |
3232
| treeNodeFilterProp | 输入项过滤对应的 treeNode 属性 | string | 'value' |
3333
| treeNodeLabelProp | 作为显示的 prop 设置 | string | 'title' |
3434
| value(v-model) | 指定当前选中的条目 | string/string\[] | - |
@@ -59,7 +59,7 @@
5959
| disableCheckbox | 禁掉 checkbox | boolean | false |
6060
| disabled | 是否禁用 | boolean | false |
6161
| isLeaf | 是否是叶子节点 | boolean | false |
62-
| key | 此项必须设置(其值在整个树范围内唯一) | string | - |
62+
| key | 此项必须设置(其值在整个树范围内唯一) | string \| number | - |
6363
| title | 树节点显示的内容 | string\|slot | '---' |
6464
| value | 默认根据此属性值进行筛选(其值在整个树范围内唯一) | string | - |
6565
| scopedSlots | 使用treeData时,可以通过该属性配置支持slot的属性,如 `scopedSlots: { title: 'XXX'}` | object | - |

components/tree-select/interface.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const TreeSelectProps = () => ({
2020
maxTagCount: PropTypes.number,
2121
maxTagPlaceholder: PropTypes.any,
2222
value: PropTypes.oneOfType([PropTypes.string, PropTypes.object, PropTypes.array]),
23-
defaultValue: PropTypes.oneOfType([PropTypes.string, PropTypes.array]),
23+
defaultValue: PropTypes.oneOfType([PropTypes.string, PropTypes.object, PropTypes.array]),
2424
multiple: PropTypes.bool,
2525
// onSelect: (value: any) => void,
2626
// onChange: (value: any, label: any) => void,
@@ -36,8 +36,8 @@ export const TreeSelectProps = () => ({
3636
dropdownClassName: PropTypes.string,
3737
dropdownMatchSelectWidth: PropTypes.bool,
3838
treeDefaultExpandAll: PropTypes.bool,
39-
treeExpandedKeys: PropTypes.arrayOf(String),
40-
treeDefaultExpandedKeys: PropTypes.arrayOf(String),
39+
treeExpandedKeys: PropTypes.array,
40+
treeDefaultExpandedKeys: PropTypes.array,
4141
treeNodeFilterProp: PropTypes.string,
4242
treeNodeLabelProp: PropTypes.string,
4343
})

components/tree/Tree.jsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,25 @@ function TreeProps () {
2323
/** 默认展开对应树节点 */
2424
defaultExpandParent: PropTypes.bool,
2525
/** 默认展开指定的树节点 */
26-
defaultExpandedKeys: PropTypes.arrayOf(String),
26+
defaultExpandedKeys: PropTypes.array,
2727
/** (受控)展开指定的树节点 */
28-
expandedKeys: PropTypes.arrayOf(String),
28+
expandedKeys: PropTypes.array,
2929
/** (受控)选中复选框的树节点 */
3030
checkedKeys: PropTypes.oneOfType(
3131
[
32-
PropTypes.arrayOf(PropTypes.string),
32+
PropTypes.array,
3333
PropTypes.shape({
34-
checked: PropTypes.arrayOf(String),
35-
halfChecked: PropTypes.arrayOf(String),
34+
checked: PropTypes.array,
35+
halfChecked: PropTypes.array,
3636
}).loose,
3737
]
3838
),
3939
/** 默认选中复选框的树节点 */
40-
defaultCheckedKeys: PropTypes.arrayOf(String),
40+
defaultCheckedKeys: PropTypes.array,
4141
/** (受控)设置选中的树节点 */
42-
selectedKeys: PropTypes.arrayOf(String),
42+
selectedKeys: PropTypes.array,
4343
/** 默认选中的树节点 */
44-
defaultSelectedKeys: PropTypes.arrayOf(String),
44+
defaultSelectedKeys: PropTypes.array,
4545
selectable: PropTypes.bool,
4646
/** 展开/收起节点时触发 */
4747
// onExpand: (expandedKeys: string[], info: AntTreeNodeExpandedEvent) => void | PromiseLike<any>,
@@ -57,7 +57,7 @@ function TreeProps () {
5757
filterAntTreeNode: PropTypes.func,
5858
/** 异步加载数据 */
5959
loadData: PropTypes.func,
60-
loadedKeys: PropTypes.arrayOf(String),
60+
loadedKeys: PropTypes.array,
6161
// onLoaded: (loadedKeys: string[], info: { event: 'load', node: AntTreeNode; }) => void,
6262
/** 响应右键点击 */
6363
// onRightClick: (options: AntTreeNodeMouseEvent) => void,
@@ -183,9 +183,7 @@ export default {
183183
__propsSymbol__: Symbol(),
184184
switcherIcon: this.renderSwitcherIcon,
185185
},
186-
on: {
187-
...this.$listeners,
188-
},
186+
on: this.$listeners,
189187
ref: 'tree',
190188
class: !showIcon && `${prefixCls}-icon-hide`,
191189
}

components/tree/index.en-US.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@
88
| treeData | treeNode of tree, please use `treeNodes` before v1.1.4 | array | - |
99
| autoExpandParent | Whether to automatically expand a parent treeNode | boolean | true |
1010
| checkable | Adds a `Checkbox` before the treeNodes | boolean | false |
11-
| checkedKeys(v-model) | (Controlled) Specifies the keys of the checked treeNodes (PS: When this specifies the key of a treeNode which is also a parent treeNode, all the children treeNodes of will be checked; and vice versa, when it specifies the key of a treeNode which is a child treeNode, its parent treeNode will also be checked. When `checkable` and `checkStrictly` is true, its object has `checked` and `halfChecked` property. Regardless of whether the child or parent treeNode is checked, they won't impact each other. | string\[] \| {checked: string\[], halfChecked: string\[]} | \[] |
11+
| checkedKeys(v-model) | (Controlled) Specifies the keys of the checked treeNodes (PS: When this specifies the key of a treeNode which is also a parent treeNode, all the children treeNodes of will be checked; and vice versa, when it specifies the key of a treeNode which is a child treeNode, its parent treeNode will also be checked. When `checkable` and `checkStrictly` is true, its object has `checked` and `halfChecked` property. Regardless of whether the child or parent treeNode is checked, they won't impact each other. | string\[] \| number\[] \| {checked: string\[] \| number\[], halfChecked: string\[] \| number\[]} | \[] |
1212
| checkStrictly | Check treeNode precisely; parent treeNode and children treeNodes are not associated | boolean | false |
13-
| defaultCheckedKeys | Specifies the keys of the default checked treeNodes | string\[] | \[] |
13+
| defaultCheckedKeys | Specifies the keys of the default checked treeNodes | string\[] \| number\[] | \[] |
1414
| defaultExpandAll | Whether to expand all treeNodes by default | boolean | false |
15-
| defaultExpandedKeys | Specify the keys of the default expanded treeNodes | string\[] | \[] |
15+
| defaultExpandedKeys | Specify the keys of the default expanded treeNodes | string\[] \| number\[] | \[] |
1616
| defaultExpandParent | auto expand parent treeNodes when init | bool | true |
17-
| defaultSelectedKeys | Specifies the keys of the default selected treeNodes | string\[] | \[] |
17+
| defaultSelectedKeys | Specifies the keys of the default selected treeNodes | string\[] \| number\[] | \[] |
1818
| disabled | whether disabled the tree | bool | false |
1919
| draggable | Specifies whether this Tree is draggable (IE > 8) | boolean | false |
20-
| expandedKeys(.sync) | (Controlled) Specifies the keys of the expanded treeNodes | string\[] | \[] |
20+
| expandedKeys(.sync) | (Controlled) Specifies the keys of the expanded treeNodes | string\[] \| number\[] | \[] |
2121
| filterTreeNode | Defines a function to filter (highlight) treeNodes. When the function returns `true`, the corresponding treeNode will be highlighted | function(node) | - |
2222
| loadData | Load data asynchronously | function(node) | - |
23-
| loadedKeys | (Controlled) Set loaded tree nodes. Need work with `loadData` | string\[] | \[] |
23+
| loadedKeys | (Controlled) Set loaded tree nodes. Need work with `loadData` | string\[] \| number\[] | \[] |
2424
| multiple | Allows selecting multiple treeNodes | boolean | false |
25-
| selectedKeys(.sync) | (Controlled) Specifies the keys of the selected treeNodes | string\[] | - |
25+
| selectedKeys(.sync) | (Controlled) Specifies the keys of the selected treeNodes | string\[] \| number\[] | - |
2626
| showIcon | Shows the icon before a TreeNode's title. There is no default style; you must set a custom style for it if set to `true` | boolean | false |
2727
| showLine | Shows a connecting line | boolean | false |
2828

@@ -54,7 +54,7 @@ One of the Tree `treeNode` prop for describing the tree's node, TreeNode has the
5454
| disabled | Disables the treeNode | boolean | false |
5555
| icon | customize icon. When you pass component, whose render will receive full TreeNode props as component props | slot\|slot-scope | - |
5656
| isLeaf | Determines if this is a leaf node(effective when `loadData` is specified) | boolean | false |
57-
| key | Used with (default)ExpandedKeys / (default)CheckedKeys / (default)SelectedKeys. P.S.: It must be unique in all of treeNodes of the tree! | string | internal calculated position of treeNode |
57+
| key | Used with (default)ExpandedKeys / (default)CheckedKeys / (default)SelectedKeys. P.S.: It must be unique in all of treeNodes of the tree! | string \| number | internal calculated position of treeNode |
5858
| selectable | Set whether the treeNode can be selected | boolean | true |
5959
| title | Title | string\|slot\|slot-scope | '---' |
6060
| slots | When using treeNodes, you can use this property to configure the properties that support the slot, such as `slots: { title: 'XXX'}` | object | - |

components/tree/index.zh-CN.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@
88
| treeData | 节点的配置描述,具体项见下表, 1.1.4之前的版本使用`treeNodes` | array | -- |
99
| autoExpandParent | 是否自动展开父节点 | boolean | true |
1010
| checkable | 节点前添加 Checkbox 复选框 | boolean | false |
11-
| checkedKeys(v-model) | (受控)选中复选框的树节点(注意:父子节点有关联,如果传入父节点key,则子节点自动选中;相应当子节点key都传入,父节点也自动选中。当设置`checkable``checkStrictly`,它是一个有`checked``halfChecked`属性的对象,并且父子节点的选中与否不再关联 | string\[] \| {checked: string\[], halfChecked: string\[]} | \[] |
11+
| checkedKeys(v-model) | (受控)选中复选框的树节点(注意:父子节点有关联,如果传入父节点key,则子节点自动选中;相应当子节点key都传入,父节点也自动选中。当设置`checkable``checkStrictly`,它是一个有`checked``halfChecked`属性的对象,并且父子节点的选中与否不再关联 | string\[] \| number\[] \| {checked: string\[] \| number\[], halfChecked: string\[] \| number\[]} | \[] |
1212
| checkStrictly | checkable状态下节点选择完全受控(父子节点选中状态不再关联) | boolean | false |
13-
| defaultCheckedKeys | 默认选中复选框的树节点 | string\[] | \[] |
13+
| defaultCheckedKeys | 默认选中复选框的树节点 | string\[] \| number\[] | \[] |
1414
| defaultExpandAll | 默认展开所有树节点 | boolean | false |
15-
| defaultExpandedKeys | 默认展开指定的树节点 | string\[] | \[] |
15+
| defaultExpandedKeys | 默认展开指定的树节点 | string\[] \| number\[] | \[] |
1616
| defaultExpandParent | 默认展开父节点 | bool | true |
17-
| defaultSelectedKeys | 默认选中的树节点 | string\[] | \[] |
17+
| defaultSelectedKeys | 默认选中的树节点 | string\[] \| number\[] | \[] |
1818
| disabled | 将树禁用 | bool | false |
1919
| draggable | 设置节点可拖拽 | boolean | false |
20-
| expandedKeys(.sync) | (受控)展开指定的树节点 | string\[] | \[] |
20+
| expandedKeys(.sync) | (受控)展开指定的树节点 | string\[] \| number\[] | \[] |
2121
| filterTreeNode | 按需筛选树节点(高亮),返回true | function(node) | - |
2222
| loadData | 异步加载数据 | function(node) | - |
23-
| loadedKeys | (受控)已经加载的节点,需要配合 `loadData` 使用 | string\[] | \[] |
23+
| loadedKeys | (受控)已经加载的节点,需要配合 `loadData` 使用 | string\[] \| number\[] | \[] |
2424
| multiple | 支持点选多个节点(节点本身) | boolean | false |
25-
| selectedKeys(.sync) | (受控)设置选中的树节点 | string\[] | - |
25+
| selectedKeys(.sync) | (受控)设置选中的树节点 | string\[] \| number\[] | - |
2626
| showIcon | 是否展示 TreeNode title 前的图标,没有默认样式,如设置为 true,需要自行定义图标相关样式 | boolean | false |
2727
| showLine | 是否展示连接线 | boolean | false |
2828

@@ -55,7 +55,7 @@
5555
| disabled | 禁掉响应 | boolean | false |
5656
| icon | 自定义图标。可接收组件,props 为当前节点 props | slot\|slot-scope | - |
5757
| isLeaf | 设置为叶子节点(设置了`loadData`时有效) | boolean | false |
58-
| key | 被树的 (default)ExpandedKeys / (default)CheckedKeys / (default)SelectedKeys 属性所用。注意:整个树范围内的所有节点的 key 值不能重复! | string | 内部计算出的节点位置 |
58+
| key | 被树的 (default)ExpandedKeys / (default)CheckedKeys / (default)SelectedKeys 属性所用。注意:整个树范围内的所有节点的 key 值不能重复! | string \| number | 内部计算出的节点位置 |
5959
| selectable | 设置节点是否可被选中 | boolean | true |
6060
| title | 标题 | string\|slot\|slot-scope | '---' |
6161
| slots | 使用treeNodes时,可以通过该属性配置支持slot的属性,如 `slots: { title: 'XXX'}` | object | - |

components/tree/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function traverseNodesKey (rootChildren, callback) {
2424

2525
export function getFullKeyList (children) {
2626
const { keyEntities } = convertTreeToEntities(children)
27-
return Object.keys(keyEntities)
27+
return [...keyEntities.keys()]
2828
}
2929

3030
/** 计算选中范围,只考虑expanded情况以优化性能 */

components/vc-tree-select/src/Base/BasePopup.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function getDerivedStateFromProps (nextProps, prevState) {
3838
filteredTreeNodes.length &&
3939
filteredTreeNodes !== prevProps.filteredTreeNodes
4040
) {
41-
newState._expandedKeyList = Object.keys(keyEntities)
41+
newState._expandedKeyList = [...keyEntities.keys()]
4242
}
4343

4444
// Cache `expandedKeyList` when filter set
@@ -56,7 +56,7 @@ function getDerivedStateFromProps (nextProps, prevState) {
5656

5757
// Clean loadedKeys if key not exist in keyEntities anymore
5858
if (nextProps.loadData) {
59-
newState._loadedKeys = loadedKeys.filter(key => key in keyEntities)
59+
newState._loadedKeys = loadedKeys.filter(key => keyEntities.has(key))
6060
}
6161

6262
return newState
@@ -70,7 +70,7 @@ const BasePopup = {
7070
valueList: PropTypes.array,
7171
searchHalfCheckedKeys: PropTypes.array,
7272
valueEntities: PropTypes.object,
73-
keyEntities: PropTypes.object,
73+
keyEntities: Map,
7474
treeIcon: PropTypes.bool,
7575
treeLine: PropTypes.bool,
7676
treeNodeFilterProp: PropTypes.string,
@@ -114,7 +114,7 @@ const BasePopup = {
114114
// TODO: make `expandedKeyList` control
115115
let expandedKeyList = treeDefaultExpandedKeys
116116
if (treeDefaultExpandAll) {
117-
expandedKeyList = Object.keys(keyEntities)
117+
expandedKeyList = [...keyEntities.keys()]
118118
}
119119

120120
const state = {

0 commit comments

Comments
 (0)