From 19b06cf55708462c1173993a71d1a2ef7bb17612 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9D=91=BE=F0=9D=92=96=F0=9D=92=99=F0=9D=92=89?= Date: Tue, 26 Nov 2024 19:03:57 +0800 Subject: [PATCH 1/2] chore: Adjust style merge order --- src/Cell/index.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Cell/index.tsx b/src/Cell/index.tsx index 90bb04a48..8b0d22162 100644 --- a/src/Cell/index.tsx +++ b/src/Cell/index.tsx @@ -212,11 +212,13 @@ function Cell(props: CellProps) { alignStyle.textAlign = align; } + // The order is important since user can overwrite style. + // For example ant-design/ant-design#51763 const mergedStyle = { + ...legacyCellProps?.style, ...fixedStyle, - ...additionalProps.style, ...alignStyle, - ...legacyCellProps?.style, + ...additionalProps.style, }; // >>>>> Children Node From 638b1b9771e19bec7cd7a156de46782fe093a38d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9D=91=BE=F0=9D=92=96=F0=9D=92=99=F0=9D=92=89?= Date: Tue, 26 Nov 2024 21:32:30 +0800 Subject: [PATCH 2/2] test: add unit test --- tests/Cell.spec.tsx | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/Cell.spec.tsx b/tests/Cell.spec.tsx index cdd558080..e06621a76 100644 --- a/tests/Cell.spec.tsx +++ b/tests/Cell.spec.tsx @@ -122,4 +122,28 @@ describe('Table.Cell', () => { expect(wrapper.find('thead th').prop('title')).toEqual('Bamboo'); }); + + // https://github.com/ant-design/ant-design/issues/51763 + it('style merge order', () => { + const wrapper = mount( + ({ + style: { + color: 'red', + textAlign: 'end', // overwrite align + }, + }), + }, + ]} + />, + ); + + expect(wrapper.find('thead th').prop('style')).toEqual({ + color: 'red', + textAlign: 'end', + }); + }); });