mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
fix(components): [tree] reconcile parent states in setCheckedKeys (#23697)
closed #22032
This commit is contained in:
@@ -805,8 +805,22 @@ describe('Tree.vue', () => {
|
||||
const tree = treeWrapper.vm as InstanceType<typeof Tree>
|
||||
|
||||
tree.setCheckedKeys([2], true)
|
||||
expect(tree.getCheckedNodes().length).toEqual(2)
|
||||
expect(tree.getCheckedKeys().length).toEqual(2)
|
||||
expect(tree.getCheckedNodes().length).toEqual(3)
|
||||
expect(tree.getCheckedKeys().length).toEqual(3)
|
||||
})
|
||||
|
||||
test('setCheckedKeys with leafOnly=true produces consistent parent states', async () => {
|
||||
const { wrapper } = getTreeVm(
|
||||
`:props="defaultProps" show-checkbox node-key="id"`
|
||||
)
|
||||
const treeWrapper = wrapper.findComponent(Tree)
|
||||
const tree = treeWrapper.vm as InstanceType<typeof Tree>
|
||||
|
||||
tree.setCheckedKeys([1], true)
|
||||
|
||||
expect(tree.getCheckedKeys().sort()).toEqual([1, 11, 111])
|
||||
expect(tree.getHalfCheckedNodes()).toEqual([])
|
||||
expect(tree.getHalfCheckedKeys()).toEqual([])
|
||||
})
|
||||
|
||||
test('setCurrentKey', async () => {
|
||||
|
||||
@@ -340,15 +340,16 @@ export default class TreeStore {
|
||||
node.setChecked(true, true)
|
||||
|
||||
if (leafOnly) {
|
||||
node.setChecked(false, false)
|
||||
node.setChecked(false, false, true)
|
||||
const traverse = function (node: Node): void {
|
||||
const childNodes = node.childNodes
|
||||
childNodes.forEach((child) => {
|
||||
if (!child.isLeaf) {
|
||||
child.setChecked(false, false)
|
||||
child.setChecked(false, false, true)
|
||||
}
|
||||
traverse(child)
|
||||
})
|
||||
node.reInitChecked()
|
||||
}
|
||||
traverse(node)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user