fix(components): [table] use isEqual to determine whether it is selected (#17885)

* fix(components): [table] use isEqual to determine whether it is selected

closed #10199, #10263

* test: add test

* test: add test
This commit is contained in:
qiang 2024-08-18 11:28:36 +08:00 committed by GitHub
parent 8fd40c900c
commit ae8328fb9c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 4 deletions

View File

@ -1,5 +1,5 @@
// @ts-nocheck
import { nextTick, ref } from 'vue'
import { nextTick } from 'vue'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import ElCheckbox from '@element-plus/components/checkbox'
import triggerEvent from '@element-plus/test-utils/trigger-event'
@ -1804,10 +1804,10 @@ describe('Table.vue', () => {
</el-table>
`,
data() {
const treeProps = ref({
const treeProps = {
children: 'childrenTest',
checkStrictly: false,
})
}
const testData = getTestData() as any
testData[1].childrenTest = [
{
@ -1849,6 +1849,12 @@ describe('Table.vue', () => {
wrapper.findAll('.el-checkbox')[2].trigger('click')
await doubleWait()
expect(wrapper.vm.selected.length).toEqual(1)
expect(wrapper.findAll('.el-checkbox')[2].classes()).include('is-checked')
wrapper.findAll('.el-checkbox')[3].trigger('click')
await doubleWait()
expect(wrapper.vm.selected.length).toEqual(2)
expect(wrapper.findAll('.el-checkbox')[3].classes()).include('is-checked')
})
})

View File

@ -1,5 +1,6 @@
// @ts-nocheck
import { getCurrentInstance, ref, toRefs, unref, watch } from 'vue'
import { isEqual } from 'lodash-unified'
import { hasOwn } from '@element-plus/utils'
import {
getColumnById,
@ -149,7 +150,7 @@ function useWatcher<T>() {
// 选择
const isSelected = (row) => {
return selection.value.includes(row)
return selection.value.some((item) => isEqual(item, row))
}
const clearSelection = () => {