diff --git a/components/input/Search.jsx b/components/input/Search.jsx index 2f2a58f6e..b0b2a5ee0 100644 --- a/components/input/Search.jsx +++ b/components/input/Search.jsx @@ -84,6 +84,7 @@ export default { }, attrs: this.$attrs, on: { + ...this.$listeners, pressEnter: this.onSearch, }, } diff --git a/components/table/index.en-US.md b/components/table/index.en-US.md index 76cf40dcd..65bf0a6e9 100644 --- a/components/table/index.en-US.md +++ b/components/table/index.en-US.md @@ -101,7 +101,6 @@ One of the Table `columns` prop for describing the table's columns, Column has t | Property | Description | Type | Default | | -------- | ----------- | ---- | ------- | -| className | className of this column | string | - | | colSpan | Span of this column's title | number | | | dataIndex | Display field of the data record, could be set like `a.b.c` | string | - | | defaultSortOrder | Default order of sorted values: `'ascend'` `'descend'` `null` | string | - | diff --git a/components/table/index.zh-CN.md b/components/table/index.zh-CN.md index 2f3a8e3fa..6def630bc 100644 --- a/components/table/index.zh-CN.md +++ b/components/table/index.zh-CN.md @@ -35,7 +35,6 @@ const columns = [{ | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | -| className | 列的 className | string | - | | bordered | 是否展示外边框和列边框 | boolean | false | | columns | 表格列的配置描述,具体项见下表 | array | - | | components | 覆盖默认的 table 元素 | object | - | diff --git a/components/tree/demo/basic-controlled.md b/components/tree/demo/basic-controlled.md index 3deb7a9f6..dae949dc7 100644 --- a/components/tree/demo/basic-controlled.md +++ b/components/tree/demo/basic-controlled.md @@ -15,11 +15,10 @@ basic controlled example @expand="onExpand" :expandedKeys="expandedKeys" :autoExpandParent="autoExpandParent" - @check="onCheck" - :checkedKeys="checkedKeys" + v-model="checkedKeys" @select="onSelect" :selectedKeys="selectedKeys" - :data="treeData" + :treeNodes="treeData" /> + ``` diff --git a/components/tree/demo/index.vue b/components/tree/demo/index.vue new file mode 100644 index 000000000..673e0d264 --- /dev/null +++ b/components/tree/demo/index.vue @@ -0,0 +1,54 @@ + diff --git a/components/tree/demo/search.md b/components/tree/demo/search.md index cd2ebdf0a..f9fbd9c86 100644 --- a/components/tree/demo/search.md +++ b/components/tree/demo/search.md @@ -10,9 +10,112 @@ Searchable Tree. ```html - + ``` diff --git a/components/tree/demo/test.vue b/components/tree/demo/test.vue deleted file mode 100644 index 1808be174..000000000 --- a/components/tree/demo/test.vue +++ /dev/null @@ -1,39 +0,0 @@ - - - diff --git a/components/tree/index.en-US.md b/components/tree/index.en-US.md index f9ec8fc28..61cdb1438 100644 --- a/components/tree/index.en-US.md +++ b/components/tree/index.en-US.md @@ -1,12 +1,3 @@ ---- -category: Components -type: Data Display -title: Tree ---- - -## When To Use - -Almost anything can be represented in a tree structure. Examples include directories, organization hierarchies, biological classifications, countries, etc. The `Tree` component is a way of representing the hierarchical relationship between these things. You can also expand, collapse, and select a treeNode within a `Tree`. ## API @@ -14,9 +5,10 @@ Almost anything can be represented in a tree structure. Examples include directo | Property | Description | Type | Default | | -------- | ----------- | ---- | ------- | +| treeNodes | treeNode of tree | array | - | | autoExpandParent | Whether to automatically expand a parent treeNode | boolean | true | | checkable | Adds a `Checkbox` before the treeNodes | boolean | false | -| checkedKeys | (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\[]} | \[] | +| 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\[]} | \[] | | checkStrictly | Check treeNode precisely; parent treeNode and children treeNodes are not associated | boolean | false | | defaultCheckedKeys | Specifies the keys of the default checked treeNodes | string\[] | \[] | | defaultExpandAll | Whether to expand all treeNodes by default | boolean | false | @@ -25,46 +17,45 @@ Almost anything can be represented in a tree structure. Examples include directo | defaultSelectedKeys | Specifies the keys of the default selected treeNodes | string\[] | \[] | | disabled | whether disabled the tree | bool | false | | draggable | Specifies whether this Tree is draggable (IE > 8) | boolean | false | -| expandedKeys | (Controlled) Specifies the keys of the expanded treeNodes | string\[] | \[] | +| expandedKeys(.sync) | (Controlled) Specifies the keys of the expanded treeNodes | string\[] | \[] | | filterTreeNode | Defines a function to filter (highlight) treeNodes. When the function returns `true`, the corresponding treeNode will be highlighted | function(node) | - | | loadData | Load data asynchronously | function(node) | - | | multiple | Allows selecting multiple treeNodes | boolean | false | -| selectedKeys | (Controlled) Specifies the keys of the selected treeNodes | string\[] | - | +| selectedKeys(.sync) | (Controlled) Specifies the keys of the selected treeNodes | string\[] | - | | 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 | | showLine | Shows a connecting line | boolean | false | -| onCheck | Callback function for when the onCheck event occurs | function(checkedKeys, e:{checked: bool, checkedNodes, node, event}) | - | -| onDragEnd | Callback function for when the onDragEnd event occurs | function({event, node}) | - | -| onDragEnter | Callback function for when the onDragEnter event occurs | function({event, node, expandedKeys}) | - | -| onDragLeave | Callback function for when the onDragLeave event occurs | function({event, node}) | - | -| onDragOver | Callback function for when the onDragOver event occurs | function({event, node}) | - | -| onDragStart | Callback function for when the onDragStart event occurs | function({event, node}) | - | -| onDrop | Callback function for when the onDrop event occurs | function({event, node, dragNode, dragNodesKeys}) | - | -| onExpand | Callback function for when a treeNode is expanded or collapsed | function(expandedKeys, {expanded: bool, node}) | - | -| onRightClick | Callback function for when the user right clicks a treeNode | function({event, node}) | - | -| onSelect | Callback function for when the user clicks a treeNode | function(selectedKeys, e:{selected: bool, selectedNodes, node, event}) | - | + +### Events +| Events Name | Description | Arguments | +| --- | --- | --- | +| check | Callback function for when the onCheck event occurs | function(checkedKeys, e:{checked: bool, checkedNodes, node, event}) | - | +| dragEnd | Callback function for when the onDragEnd event occurs | function({event, node}) | - | +| dragEnter | Callback function for when the onDragEnter event occurs | function({event, node, expandedKeys}) | - | +| dragLeave | Callback function for when the onDragLeave event occurs | function({event, node}) | - | +| dragOver | Callback function for when the onDragOver event occurs | function({event, node}) | - | +| dragStart | Callback function for when the onDragStart event occurs | function({event, node}) | - | +| drop | Callback function for when the onDrop event occurs | function({event, node, dragNode, dragNodesKeys}) | - | +| expand | Callback function for when a treeNode is expanded or collapsed | function(expandedKeys, {expanded: bool, node}) | - | +| rightClick | Callback function for when the user right clicks a treeNode | function({event, node}) | - | +| select | Callback function for when the user clicks a treeNode | function(selectedKeys, e:{selected: bool, selectedNodes, node, event}) | - | ### TreeNode props + +One of the Tree `treeNode` prop for describing the tree's node, TreeNode has the same API. + | Property | Description | Type | Default | | -------- | ----------- | ---- | ------- | +| class | className | string | - | +| style | style | string\|object | - | | disableCheckbox | Disables the checkbox of the treeNode | boolean | false | | disabled | Disables the treeNode | boolean | false | -| icon | customize icon. When you pass component, whose render will receive full TreeNode props as component props | element/Function(props):ReactNode | - | +| icon | customize icon. When you pass component, whose render will receive full TreeNode props as component props | slot\|slot-scope | - | | isLeaf | Determines if this is a leaf node(effective when `loadData` is specified) | boolean | false | | 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 | | selectable | Set whether the treeNode can be selected | boolean | true | -| title | Title | string\|ReactNode | '---' | +| title | Title | string\|slot\|slot-scope | '---' | +| slots | When using treeNodes, you can use this property to configure the properties that support the slot, such as `slots: { title: 'XXX'}` | object | - | +| scopedSlots | When using treeNodes, you can use this property to configure the properties that support the slot-scope, such as `scopedSlots: { title: 'XXX'}` | object | - | +| on | When using treeNodes, you can use this property to configure the events, such as `on: { click: () => {}}` | object | - | -## Note - -Before `3.4.0`: -The number of treeNodes can be very large, but when `checkable=true`, -it will increase the compute time. So, we cache some calculations (e.g. `this.treeNodesStates`) -to avoid double computing. But, this brings some restrictions. -**When you load treeNodes asynchronously, you should render tree like this**: - -```jsx -{this.state.treeData.length - ? {this.state.treeData.map(data => )} - : 'loading tree'} -``` diff --git a/components/tree/index.jsx b/components/tree/index.jsx index 6c16b9ccf..43bf9ccd3 100644 --- a/components/tree/index.jsx +++ b/components/tree/index.jsx @@ -30,7 +30,7 @@ import { initDefaultProps, getOptionProps } from '../_util/props-util' // } export const TreeProps = () => ({ - data: PropTypes.array, + treeNodes: PropTypes.array, showLine: PropTypes.bool, /** 是否支持多选 */ multiple: PropTypes.boolean, @@ -127,7 +127,9 @@ export default { icon: restProps.icon || $slots[slots.icon] || ($scopedSlots[scopedSlots.icon] && $scopedSlots[scopedSlots.icon]), - title: restProps.title || $slots[slots.title], + title: restProps.title || + $slots[slots.title] || + ($scopedSlots[scopedSlots.title] && $scopedSlots[scopedSlots.title])(item), dataRef: item, }, on, @@ -149,7 +151,7 @@ export default { render () { const props = getOptionProps(this) - const { prefixCls, checkable, data, ...restProps } = props + const { prefixCls, checkable, treeNodes, ...restProps } = props const { handelSelect, handleCheck, handleExpand, renderTreeNodes } = this const vcTreeProps = { props: { @@ -166,7 +168,7 @@ export default { } return ( - {data ? renderTreeNodes(data) : this.$slots.default} + {treeNodes ? renderTreeNodes(treeNodes) : this.$slots.default} ) }, diff --git a/components/tree/index.zh-CN.md b/components/tree/index.zh-CN.md index 7c908a96a..d77856e44 100644 --- a/components/tree/index.zh-CN.md +++ b/components/tree/index.zh-CN.md @@ -1,13 +1,3 @@ ---- -category: Components -type: Data Display -title: Tree -subtitle: 树形控件 ---- - -## 何时使用 - -文件夹、组织架构、生物分类、国家地区等等,世间万物的大多数结构都是树形结构。使用`树控件`可以完整展现其中的层级关系,并具有展开收起选择等交互功能。 ## API @@ -15,9 +5,10 @@ subtitle: 树形控件 | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | +| treeNodes | 节点的配置描述,具体项见下表 | array | -- | | autoExpandParent | 是否自动展开父节点 | boolean | true | | checkable | 节点前添加 Checkbox 复选框 | boolean | false | -| checkedKeys | (受控)选中复选框的树节点(注意:父子节点有关联,如果传入父节点key,则子节点自动选中;相应当子节点key都传入,父节点也自动选中。当设置`checkable`和`checkStrictly`,它是一个有`checked`和`halfChecked`属性的对象,并且父子节点的选中与否不再关联 | string\[] \| {checked: string\[], halfChecked: string\[]} | \[] | +| checkedKeys(v-model) | (受控)选中复选框的树节点(注意:父子节点有关联,如果传入父节点key,则子节点自动选中;相应当子节点key都传入,父节点也自动选中。当设置`checkable`和`checkStrictly`,它是一个有`checked`和`halfChecked`属性的对象,并且父子节点的选中与否不再关联 | string\[] \| {checked: string\[], halfChecked: string\[]} | \[] | | checkStrictly | checkable状态下节点选择完全受控(父子节点选中状态不再关联) | boolean | false | | defaultCheckedKeys | 默认选中复选框的树节点 | string\[] | \[] | | defaultExpandAll | 默认展开所有树节点 | boolean | false | @@ -25,44 +16,49 @@ subtitle: 树形控件 | defaultExpandParent | 默认展开父节点 | bool | true | | defaultSelectedKeys | 默认选中的树节点 | string\[] | \[] | | disabled | 将树禁用 | bool | false | -| draggable | 设置节点可拖拽(IE>8) | boolean | false | -| expandedKeys | (受控)展开指定的树节点 | string\[] | \[] | +| draggable | 设置节点可拖拽 | boolean | false | +| expandedKeys(.sync) | (受控)展开指定的树节点 | string\[] | \[] | | filterTreeNode | 按需筛选树节点(高亮),返回true | function(node) | - | | loadData | 异步加载数据 | function(node) | - | | multiple | 支持点选多个节点(节点本身) | boolean | false | -| selectedKeys | (受控)设置选中的树节点 | string\[] | - | +| selectedKeys(.sync) | (受控)设置选中的树节点 | string\[] | - | | showIcon | 是否展示 TreeNode title 前的图标,没有默认样式,如设置为 true,需要自行定义图标相关样式 | boolean | false | | showLine | 是否展示连接线 | boolean | false | -| onCheck | 点击复选框触发 | function(checkedKeys, e:{checked: bool, checkedNodes, node, event}) | - | -| onDragEnd | dragend 触发时调用 | function({event, node}) | - | -| onDragEnter | dragenter 触发时调用 | function({event, node, expandedKeys}) | - | -| onDragLeave | dragleave 触发时调用 | function({event, node}) | - | -| onDragOver | dragover 触发时调用 | function({event, node}) | - | -| onDragStart | 开始拖拽时调用 | function({event, node}) | - | -| onDrop | drop 触发时调用 | function({event, node, dragNode, dragNodesKeys}) | - | -| onExpand | 展开/收起节点时触发 | function(expandedKeys, {expanded: bool, node}) | - | -| onRightClick | 响应右键点击 | function({event, node}) | - | -| onSelect | 点击树节点触发 | function(selectedKeys, e:{selected: bool, selectedNodes, node, event}) | - | + + +### 事件 + +| 事件名称 | 说明 | 回调参数 | +| --- | --- | --- | +| check | 点击复选框触发 | function(checkedKeys, e:{checked: bool, checkedNodes, node, event}) | - | +| dragEnd | dragend 触发时调用 | function({event, node}) | - | +| dragEnter | dragenter 触发时调用 | function({event, node, expandedKeys}) | - | +| dragLeave | dragleave 触发时调用 | function({event, node}) | - | +| dragOver | dragover 触发时调用 | function({event, node}) | - | +| dragStart | 开始拖拽时调用 | function({event, node}) | - | +| drop | drop 触发时调用 | function({event, node, dragNode, dragNodesKeys}) | - | +| expand | 展开/收起节点时触发 | function(expandedKeys, {expanded: bool, node}) | - | +| rightClick | 响应右键点击 | function({event, node}) | - | +| select | 点击树节点触发 | function(selectedKeys, e:{selected: bool, selectedNodes, node, event}) | - | ### TreeNode props +结点描述数据对象,是 treeNodes 中的一项,TreeNode 使用相同的 API。 + | 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | +| class | 节点的 class | string | - | +| style | 节点的 style | string\|object | - | | disableCheckbox | 禁掉 checkbox | boolean | false | | disabled | 禁掉响应 | boolean | false | -| icon | 自定义图标。可接收组件,props 为当前节点 props | element/Function(props):ReactNode | - | +| icon | 自定义图标。可接收组件,props 为当前节点 props | slot\|slot-scope | - | | isLeaf | 设置为叶子节点(设置了`loadData`时有效) | boolean | false | | key | 被树的 (default)ExpandedKeys / (default)CheckedKeys / (default)SelectedKeys 属性所用。注意:整个树范围内的所有节点的 key 值不能重复! | string | 内部计算出的节点位置 | | selectable | 设置节点是否可被选中 | boolean | true | -| title | 标题 | string\|ReactNode | '---' | +| title | 标题 | string\|slot\|slot-scope | '---' | +| slots | 使用treeNodes时,可以通过该属性配置支持slot的属性,如 `slots: { title: 'XXX'}` | object | - | +| scopedSlots | 使用columns时,可以通过该属性配置支持slot-scope的属性,如 `scopedSlots: { title: 'XXX'}` | object | - | +| on | 事件对象,仅在treeNodes使用方式中生效,如`{click: () => {}}` | object | '---' | -## 注意 -在 `3.4.0` 之前: -树节点可以有很多,但在设置`checkable`时,将会花费更多的计算时间,因此我们缓存了一些计算结果(`this.treeNodesStates`)来复用,避免多次重复计算,以此提高性能。但这也带来了一些限制,当你异步加载树节点时,你需要这样渲染树: -```jsx -{this.state.treeData.length - ? {this.state.treeData.map(data => )} - : 'loading tree'} -``` diff --git a/site/demo.js b/site/demo.js index a71a8e877..bed407c3d 100644 --- a/site/demo.js +++ b/site/demo.js @@ -42,3 +42,4 @@ export { default as table } from 'antd/table/demo/index.vue' export { default as inputNumber } from 'antd/input-number/demo/index.vue' export { default as transfer } from 'antd/transfer/demo/index.vue' export { default as upload } from 'antd/upload/demo/index.vue' +export { default as tree } from 'antd/tree/demo/index.vue' diff --git a/site/routes.js b/site/routes.js index 64b7a3110..e969297dd 100644 --- a/site/routes.js +++ b/site/routes.js @@ -3,7 +3,7 @@ import Layout from './components/layout.vue' const AsyncTestComp = () => { const d = window.location.hash.replace('#', '') return { - component: import(`../components/slider/demo/${d}`), + component: import(`../components/tree/demo/${d}`), } }