fix(components): [table] selection fixed unexpected (#17904)

* fix(components): [table] selection fixed unexpected

* perf(components): [table] selection fixed unexpected

* perf(components): [table] selection fixed unexpected
This commit is contained in:
betavs 2024-09-13 14:45:12 +08:00 committed by GitHub
parent 28083c2646
commit 107eac00a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 6 deletions

View File

@ -1121,7 +1121,8 @@ describe('table column', () => {
},
template: `
<el-table :data="testData">
<el-table-column :fixed="fixed" />
<el-table-column type="selection" />
<el-table-column :fixed="fixed" prop="name" />
<el-table-column prop="release" />
<el-table-column prop="director" />
<el-table-column prop="runtime" />
@ -1144,6 +1145,9 @@ describe('table column', () => {
wrapper.vm.fixed = true
await doubleWait()
expect(wrapper.find('.el-table-fixed-column--left').exists()).toBeTruthy()
wrapper.vm.fixed = false
await doubleWait()
expect(wrapper.find('.el-table-fixed-column--left').exists()).toBeFalsy()
wrapper.unmount()
})

View File

@ -1,7 +1,7 @@
// @ts-nocheck
import { getCurrentInstance, ref, toRefs, unref, watch } from 'vue'
import { isEqual } from 'lodash-unified'
import { hasOwn } from '@element-plus/utils'
import { hasOwn, isUndefined } from '@element-plus/utils'
import {
getColumnById,
getColumnByKey,
@ -94,6 +94,8 @@ function useWatcher<T>() {
})
}
let selectionInitialFixed = undefined
// 更新列
const updateColumns = () => {
_columns.value.forEach((column) => {
@ -105,14 +107,35 @@ function useWatcher<T>() {
rightFixedColumns.value = _columns.value.filter(
(column) => column.fixed === 'right'
)
if (
isUndefined(selectionInitialFixed) &&
_columns.value[0] &&
_columns.value[0].type === 'selection'
) {
selectionInitialFixed = Boolean(_columns.value[0].fixed)
}
if (
fixedColumns.value.length > 0 &&
_columns.value[0] &&
_columns.value[0].type === 'selection' &&
!_columns.value[0].fixed
_columns.value[0].type === 'selection'
) {
_columns.value[0].fixed = true
fixedColumns.value.unshift(_columns.value[0])
if (!_columns.value[0].fixed) {
_columns.value[0].fixed = true
fixedColumns.value.unshift(_columns.value[0])
} else {
const hasNotSelectionColumns = fixedColumns.value.some(
(column) => column.type !== 'selection'
)
if (!hasNotSelectionColumns) {
_columns.value[0].fixed = selectionInitialFixed
if (!selectionInitialFixed) fixedColumns.value.shift()
} else {
selectionInitialFixed = undefined
}
}
}
const notFixedColumns = _columns.value.filter((column) => !column.fixed)