Skip to content

Commit

Permalink
chore: Adjust style merge order (#1207)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wxh16144 authored Nov 26, 2024
1 parent 7780307 commit f3d7284
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Cell/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,13 @@ function Cell<RecordType>(props: CellProps<RecordType>) {
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
Expand Down
24 changes: 24 additions & 0 deletions tests/Cell.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<Table
columns={[
{
align: 'center',
onHeaderCell: () => ({
style: {
color: 'red',
textAlign: 'end', // overwrite align
},
}),
},
]}
/>,
);

expect(wrapper.find('thead th').prop('style')).toEqual({
color: 'red',
textAlign: 'end',
});
});
});

0 comments on commit f3d7284

Please sign in to comment.