fix(components): [tree-select] incorrect selection when using checkOnClickNode without checkbox (#12826)

This commit is contained in:
yujinpan 2023-05-15 19:24:14 +08:00 committed by GitHub
parent 7424a78e80
commit e82c5b36d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 0 deletions

View File

@ -643,4 +643,37 @@ describe('TreeSelect.vue', () => {
expect(modelValue.value).toEqual([])
})
test('no checkbox and check on click node', async () => {
const { select, tree } = createComponent({
props: {
checkOnClickNode: true,
data: [
{ value: 1, label: '1' },
{ value: 2, label: '2' },
],
},
})
const nodes = tree.findAll('.el-tree-node__content')
await nodes[0].trigger('click')
await nextTick()
expect(select.vm.modelValue).equal(1)
// click again not to deselect
await nodes[0].trigger('click')
await nextTick()
expect(select.vm.modelValue).equal(1)
// can correctly choose another
await nodes.slice(-1)[0].trigger('click')
await nextTick()
expect(select.vm.modelValue).equal(2)
// again
await nodes.slice(-1)[0].trigger('click')
await nextTick()
expect(select.vm.modelValue).equal(2)
})
})

View File

@ -177,6 +177,9 @@ export const useTree = (
}
},
onCheck: (data, params) => {
// ignore when no checkbox, like only `checkOnClickNode` is true
if (!props.showCheckbox) return
const dataValue = getNodeValByProp('value', data)
// fix: checkedKeys has not cached keys