fix(components): [tree-v2] modify the condition for when the value of currentKey is 0 (#13935)

* modify the condition for when the value of currentKey is 0

* add a test case

* add a test case

* add a test case

* Update packages/components/tree-v2/__tests__/tree.test.ts

Co-authored-by: btea <2356281422@qq.com>

* Update packages/components/tree-v2/__tests__/tree.test.ts

Co-authored-by: btea <2356281422@qq.com>

* Update packages/components/tree-v2/__tests__/tree.test.ts

Co-authored-by: btea <2356281422@qq.com>

---------

Co-authored-by: btea <2356281422@qq.com>
This commit is contained in:
zepeng 2023-08-14 12:49:36 +08:00 committed by GitHub
parent 067028ba3c
commit 665cc59b19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 1 deletions

View File

@ -1176,5 +1176,65 @@ describe('Virtual Tree', () => {
})
expect(treeRef.getCurrentKey()).toBe('1-1-2')
})
test('setCurrentKey', async () => {
const { treeRef, wrapper } = createTree({
data() {
return {
data: [
{
id: 0,
label: 'node-0',
},
{
id: '1',
label: 'node-1',
children: [
{
id: '1-1',
label: 'node-1-1',
children: [
{
id: '1-1-1',
label: 'node-1-1-1',
},
{
id: '1-1-2',
label: 'node-1-1-2',
},
],
},
{
id: '1-2',
label: 'node-1-2',
children: [
{
id: '1-2-1',
label: 'node-1-2-1',
},
],
},
{
id: '1-3',
label: 'node-1-3',
},
],
},
{
id: '2',
label: 'node-2',
},
],
}
},
})
await nextTick()
treeRef.setCurrentKey(0)
await nextTick()
const currentKeys = treeRef.getCurrentKey()
const nodes = wrapper.findAll(TREE_NODE_CLASS_NAME)
expect(currentKeys).toBe(0)
expect(nodes[0].classes()).toContain('is-current')
})
})
})

View File

@ -253,7 +253,7 @@ export function useTree(
function isCurrent(node: TreeNode): boolean {
const current = currentKey.value
return !!current && current === node.key
return current !== undefined && current === node.key
}
function getCurrentNode(): TreeNodeData | undefined {