fix(cascader-panel): no loaded nodes should not be checked (#1583)

* fix(cascader): no loaded nodes should not be checked

* fix(cascader): no loaded nodes should not be checked

* fix(cascader): it should be indeterminate if some child are not loaded
This commit is contained in:
Ernest 2021-03-10 20:30:28 +08:00 committed by GitHub
parent 1655c2aa11
commit 598b798555
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 2 deletions

View File

@ -578,6 +578,57 @@ describe('CascaderPanel.vue', () => {
expect(wrapper.find(`.is-active`).text()).toBe('option2')
})
test('no loaded nodes should not be checked', async () => {
const wrapper = _mount({
template: `
<cascader-panel
:props="props"
/>
`,
data() {
return {
props: {
multiple: true,
lazy: true,
lazyLoad (node, resolve) {
const { level } = node
setTimeout(() => {
const nodes = Array.from({ length: level + 1 })
.map(() => {
++id
return {
value: id,
label: `option${id}`,
leaf: id === 3,
}
})
resolve(nodes)
}, 1000)
},
},
}
},
})
jest.runAllTimers()
await nextTick()
const firstMenu = wrapper.findAll(MENU)[0]
const firstOption = wrapper.find(NODE)
await firstOption.trigger('click')
jest.runAllTimers()
await nextTick()
await firstMenu.find(CHECKBOX).find('input').trigger('click')
const secondMenu = wrapper.findAll(MENU)[1]
expect(secondMenu.exists()).toBe(true)
expect(firstMenu.find(CHECKBOX).classes('is-checked')).toBe(false)
expect(firstMenu.find(CHECKBOX).classes('is-indeterminate')).toBe(true)
expect(secondMenu.findAll(CHECKBOX)[0].classes('is-checked')).toBe(false)
expect(secondMenu.findAll(CHECKBOX)[0].classes('is-indeterminate')).toBe(false)
expect(secondMenu.findAll(CHECKBOX)[1].classes('is-checked')).toBe(true)
expect(secondMenu.findAll(CHECKBOX)[1].classes('is-indeterminate')).toBe(false)
})
test('getCheckedNodes and clearCheckedNodes', () => {
const wrapper = mount(CascaderPanel, {
props: {

View File

@ -147,8 +147,8 @@ export default class Node {
return c + num
}, 0)
this.checked = checked
this.indeterminate = checkedNum !== totalNum && checkedNum > 0
this.checked = this.loaded && this.children.every(child => child.loaded && child.checked) && checked
this.indeterminate = this.loaded && checkedNum !== totalNum && checkedNum > 0
}
doCheck(checked: boolean) {