Skip to content

Commit aa6a077

Browse files
committed
fix: Missing render with style & className
fix ant-design/ant-design#21354
1 parent 50a105b commit aa6a077

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/Cell/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ function Cell<RecordType extends DefaultRecordType>(
114114
childNode = <span className={`${cellPrefixCls}-content`}>{childNode}</span>;
115115
}
116116

117-
const { colSpan: cellColSpan, rowSpan: cellRowSpan } = cellProps || {};
117+
const { colSpan: cellColSpan, rowSpan: cellRowSpan, style: cellStyle, className: cellClassName } =
118+
cellProps || {};
118119
const mergedColSpan = cellColSpan !== undefined ? cellColSpan : colSpan;
119120
const mergedRowSpan = cellRowSpan !== undefined ? cellRowSpan : rowSpan;
120121

@@ -169,8 +170,9 @@ function Cell<RecordType extends DefaultRecordType>(
169170
[`${cellPrefixCls}-with-append`]: appendNode,
170171
},
171172
additionalProps.className,
173+
cellClassName,
172174
),
173-
style: { ...additionalProps.style, ...alignStyle, ...fixedStyle },
175+
style: { ...additionalProps.style, ...alignStyle, ...fixedStyle, ...cellStyle },
174176
ref: isRefComponent(Component) ? ref : null,
175177
};
176178

tests/Table.spec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,26 @@ describe('Table.Basic', () => {
299299
expect(wrapper.render()).toMatchSnapshot();
300300
});
301301

302+
it('render with style & className', () => {
303+
const columns = [
304+
{
305+
dataIndex: 'key',
306+
render: text => ({
307+
props: {
308+
style: { background: 'red' },
309+
className: 'customize-render',
310+
},
311+
children: text,
312+
}),
313+
},
314+
];
315+
316+
const wrapper = mount(<Table columns={columns} data={[{ key: '' }]} />);
317+
const props = wrapper.find('td').props();
318+
expect(props.style).toEqual(expect.objectContaining({ background: 'red' }));
319+
expect(props.className.includes('customize-render')).toBeTruthy();
320+
});
321+
302322
it('renders rowSpan correctly', () => {
303323
const columns = [
304324
{

0 commit comments

Comments
 (0)