Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Adjust style merge order #1207

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
});
});
});