mirror of
https://github.com/element-plus/element-plus.git
synced 2024-11-27 02:01:15 +08:00
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:
parent
c3dc4b304e
commit
43c8f35412
@ -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: {
|
||||
|
@ -155,8 +155,8 @@ function useWatcher<T>() {
|
||||
const clearSelection = () => {
|
||||
isAllSelected.value = false
|
||||
const oldSelection = selection.value
|
||||
selection.value = []
|
||||
if (oldSelection.length) {
|
||||
selection.value = []
|
||||
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 = () => {
|
||||
|
Loading…
Reference in New Issue
Block a user