fix(components): [table] selection reference when toggleAllSelection (#16800)

* fix(components): [table] selection is not updated when length is 0

* fix(components): [table] selection reference when toggleAllSelection

* feat: add test
This commit is contained in:
Liao-js 2024-05-10 20:24:11 +08:00 committed by GitHub
parent c3dc4b304e
commit 43c8f35412
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 42 additions and 2 deletions

View File

@ -790,6 +790,46 @@ describe('Table.vue', () => {
wrapper.unmount()
})
it('selection reference', async () => {
const wrapper = mount({
components: {
ElTableColumn,
ElTable,
},
template: `
<el-table ref="table" :data="testData" @select-all="handleSelectAll">
<el-table-column prop="name" />
<el-table-column prop="release" />
<el-table-column prop="director" />
<el-table-column prop="runtime"/>
</el-table>
`,
data() {
return {
testData: getTestData(),
selection: null,
}
},
methods: {
handleSelectAll(selection) {
this.selection = selection
},
},
})
const vm = wrapper.vm
vm.$refs.table.toggleAllSelection()
await doubleWait()
const oldSelection = vm.selection
vm.$refs.table.toggleAllSelection()
await doubleWait()
const newSelection = vm.selection
vm.$refs.table.clearSelection()
expect(oldSelection !== newSelection).toBe(true)
wrapper.unmount()
})
it('sort', async () => {
const wrapper = mount({
components: {

View File

@ -155,8 +155,8 @@ function useWatcher<T>() {
const clearSelection = () => {
isAllSelected.value = false
const oldSelection = selection.value
if (oldSelection.length) {
selection.value = []
if (oldSelection.length) {
instance.emit('selection-change', [])
}
}
@ -238,7 +238,7 @@ function useWatcher<T>() {
selection.value ? selection.value.slice() : []
)
}
instance.emit('select-all', selection.value)
instance.emit('select-all', (selection.value || []).slice())
}
const updateSelectionByRowKey = () => {