fix(components): [table] selection-change event emit incorrectly (#19618)

* feat(components): [table] fix 'selection-change' event emit incorrectly

* fix(components): [table] add test case
This commit is contained in:
Nick Wu
2025-01-18 18:36:06 +08:00
committed by GitHub
parent 40a616ea1a
commit fc1a0b8d60
2 changed files with 19 additions and 1 deletions

View File

@@ -1848,12 +1848,14 @@ describe('Table.vue', () => {
const testData = getTestData() as any
testData[1].childrenTest = [
{
id: 21,
name: "A Bug's Life copy 1",
release: '1998-11-25-1',
director: 'John Lasseter',
runtime: 95,
},
{
id: 22,
name: "A Bug's Life copy 2",
release: '1998-11-25-2',
director: 'John Lasseter',
@@ -1892,6 +1894,19 @@ describe('Table.vue', () => {
await doubleWait()
expect(wrapper.vm.selected.length).toEqual(2)
expect(wrapper.findAll('.el-checkbox')[3].classes()).include('is-checked')
await (wrapper.vm.treeProps.checkStrictly = false)
wrapper.findAll('.el-checkbox')[0].trigger('click')
wrapper.findAll('.el-checkbox')[0].trigger('click')
await doubleWait()
expect(wrapper.vm.selected.length).toEqual(0)
wrapper.findAll('.el-checkbox')[0].trigger('click')
await doubleWait()
wrapper.findAll('.el-checkbox')[3].trigger('click')
await doubleWait()
wrapper.findAll('.el-checkbox')[0].trigger('click')
await doubleWait()
expect(wrapper.vm.selected.length).toEqual(getTestData().length + 2)
})
})

View File

@@ -318,7 +318,7 @@ export function toggleRowStatus<T>(
isArray(row[tableTreeProps.children])
) {
row[tableTreeProps.children].forEach((item) => {
toggleRowStatus(
const childChanged = toggleRowStatus(
statusArr,
item,
newVal ?? !included,
@@ -327,6 +327,9 @@ export function toggleRowStatus<T>(
_rowIndex + 1
)
_rowIndex += getChildrenCount(item) + 1
if (childChanged) {
changed = childChanged
}
})
}
return changed