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,