fix(components): [table-v2] respect column flexShrink configuration (#22914)

closed #22913

Co-authored-by: alex.yang <alex.yang@hytechc.com>
Co-authored-by: 云游君 <me@yunyoujun.cn>
This commit is contained in:
mortis.yi
2026-01-03 18:24:42 +08:00
committed by GitHub
parent 4b04769769
commit 8bc34fd8d7
2 changed files with 42 additions and 6 deletions

View File

@@ -188,6 +188,46 @@ describe('TableV2.vue', () => {
)
})
test('respects column flexShrink = 0', async () => {
const columns = ref([
{
key: 'col-0',
dataKey: 'col-0',
title: 'Col 0',
width: 200,
flexShrink: 0,
},
{
key: 'col-1',
dataKey: 'col-1',
title: 'Col 1',
width: 200,
flexShrink: 0,
},
])
const data = ref([
{
id: 'row-0',
'col-0': 'Row 0 - Col 0',
'col-1': 'Row 0 - Col 1',
},
])
const wrapper = mount(() => (
<TableV2
columns={columns.value}
data={data.value}
width={300}
height={200}
/>
))
const rowCells = wrapper.findAll('.el-table-v2__row-cell')
expect(rowCells.length).toBeGreaterThanOrEqual(2)
expect(rowCells[0].attributes('style')).toContain('flex-shrink: 0;')
expect(rowCells[1].attributes('style')).toContain('flex-shrink: 0;')
})
test('expandable mode wrongly enabled, by column not key', async () => {
const columns = ref([
{

View File

@@ -12,15 +12,11 @@ export const calcColumnStyle = (
...(fixed
? {}
: {
flexGrow: column.flexGrow || 0,
flexShrink: column.flexShrink || 1,
flexGrow: column.flexGrow ?? 0,
flexShrink: column.flexShrink ?? 1,
}),
}
if (!fixed) {
flex.flexShrink = 1
}
const style = {
...(column.style ?? {}),
...flex,