Skip to content

Commit

Permalink
fix(components): [table] selection reference when toggleAllSelection (e…
Browse files Browse the repository at this point in the history
…lement-plus#16800)

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

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

* feat: add test
  • Loading branch information
Liao-js committed May 10, 2024
1 parent c3dc4b3 commit 43c8f35
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
40 changes: 40 additions & 0 deletions packages/components/table/__tests__/table.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
4 changes: 2 additions & 2 deletions packages/components/table/src/store/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', [])
}
}
Expand Down Expand Up @@ -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 = () => {
Expand Down

0 comments on commit 43c8f35

Please sign in to comment.