Skip to content

Commit 4439e0f

Browse files
committed
feat: tree add scrollTo method, close #5626
1 parent 5edca6b commit 4439e0f

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

components/tree/Tree.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import VcTree from '../vc-tree';
55
import PropTypes from '../_util/vue-types';
66
import { filterEmpty } from '../_util/props-util';
77
import initDefaultProps from '../_util/props-util/initDefaultProps';
8-
import type { DataNode, EventDataNode, FieldNames, Key } from '../vc-tree/interface';
8+
import type { DataNode, EventDataNode, FieldNames, Key, ScrollTo } from '../vc-tree/interface';
99
import type { TreeNodeProps } from '../vc-tree/props';
1010
import { treeProps as vcTreeProps } from '../vc-tree/props';
1111
import useConfigInject from '../_util/hooks/useConfigInject';
@@ -168,11 +168,15 @@ export default defineComponent({
168168
);
169169
const { prefixCls, direction, virtual } = useConfigInject('tree', props);
170170
const treeRef = ref();
171+
const scrollTo: ScrollTo = scroll => {
172+
treeRef.value?.scrollTo(scroll);
173+
};
171174
expose({
172175
treeRef,
173176
onNodeExpand: (...args) => {
174177
treeRef.value?.onNodeExpand(...args);
175178
},
179+
scrollTo,
176180
selectedKeys: computed(() => treeRef.value?.selectedKeys),
177181
checkedKeys: computed(() => treeRef.value?.checkedKeys),
178182
halfCheckedKeys: computed(() => treeRef.value?.halfCheckedKeys),

components/tree/index.en-US.md

+6
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ Almost anything can be represented in a tree structure. Examples include directo
5656
| rightClick | Callback function for when the user right clicks a treeNode | function({event, node}) |
5757
| select | Callback function for when the user clicks a treeNode | function(selectedKeys, e:{selected: bool, selectedNodes, node, event}) |
5858

59+
### Tree Methods
60+
61+
| Name | Description |
62+
| --- | --- |
63+
| scrollTo({ key: string \| number; align?: 'top' \| 'bottom' \| 'auto'; offset?: number }) | Scroll to key item in virtual scroll |
64+
5965
### TreeNode
6066

6167
| Property | Description | Type | Default | Version |

components/tree/index.zh-CN.md

+6
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ cover: https://gw.alipayobjects.com/zos/alicdn/Xh-oWqg9k/Tree.svg
5757
| rightClick | 响应右键点击 | function({event, node}) |
5858
| select | 点击树节点触发 | function(selectedKeys, e:{selected: bool, selectedNodes, node, event}) |
5959

60+
### Tree 方法
61+
62+
| 名称 | 说明 |
63+
| --- | --- |
64+
| scrollTo({ key: string \| number; align?: 'top' \| 'bottom' \| 'auto'; offset?: number }) | 虚拟滚动下,滚动到指定 key 条目 |
65+
6066
### TreeNode
6167

6268
| 参数 | 说明 | 类型 | 默认值 | 版本 |

0 commit comments

Comments
 (0)