From 8bc34fd8d7e2009da81094cb35302d2a832fb123 Mon Sep 17 00:00:00 2001 From: "mortis.yi" <33254923+yicheny@users.noreply.github.com> Date: Sat, 3 Jan 2026 18:24:42 +0800 Subject: [PATCH] fix(components): [table-v2] respect column flexShrink configuration (#22914) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closed #22913 Co-authored-by: alex.yang Co-authored-by: 云游君 --- .../table-v2/__tests__/table-v2.test.tsx | 40 +++++++++++++++++++ .../table-v2/src/composables/utils.ts | 8 +--- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/packages/components/table-v2/__tests__/table-v2.test.tsx b/packages/components/table-v2/__tests__/table-v2.test.tsx index d69a45577b..ae3fae1db4 100644 --- a/packages/components/table-v2/__tests__/table-v2.test.tsx +++ b/packages/components/table-v2/__tests__/table-v2.test.tsx @@ -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(() => ( + + )) + + 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([ { diff --git a/packages/components/table-v2/src/composables/utils.ts b/packages/components/table-v2/src/composables/utils.ts index 642efa7ed0..c734921c86 100644 --- a/packages/components/table-v2/src/composables/utils.ts +++ b/packages/components/table-v2/src/composables/utils.ts @@ -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,