Skip to content

Commit f3d7284

Browse files
authored
chore: Adjust style merge order (#1207)
1 parent 7780307 commit f3d7284

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/Cell/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,13 @@ function Cell<RecordType>(props: CellProps<RecordType>) {
212212
alignStyle.textAlign = align;
213213
}
214214

215+
// The order is important since user can overwrite style.
216+
// For example ant-design/ant-design#51763
215217
const mergedStyle = {
218+
...legacyCellProps?.style,
216219
...fixedStyle,
217-
...additionalProps.style,
218220
...alignStyle,
219-
...legacyCellProps?.style,
221+
...additionalProps.style,
220222
};
221223

222224
// >>>>> Children Node

tests/Cell.spec.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,28 @@ describe('Table.Cell', () => {
122122

123123
expect(wrapper.find('thead th').prop('title')).toEqual('Bamboo');
124124
});
125+
126+
// https://github.com/ant-design/ant-design/issues/51763
127+
it('style merge order', () => {
128+
const wrapper = mount(
129+
<Table
130+
columns={[
131+
{
132+
align: 'center',
133+
onHeaderCell: () => ({
134+
style: {
135+
color: 'red',
136+
textAlign: 'end', // overwrite align
137+
},
138+
}),
139+
},
140+
]}
141+
/>,
142+
);
143+
144+
expect(wrapper.find('thead th').prop('style')).toEqual({
145+
color: 'red',
146+
textAlign: 'end',
147+
});
148+
});
125149
});

0 commit comments

Comments
 (0)