mirror of
https://github.com/element-plus/element-plus.git
synced 2024-11-27 02:01:15 +08:00
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:
parent
067028ba3c
commit
665cc59b19
@ -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')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user