fix(Button): child element's className being cleared when rendering two Chinese characters. (#56593)

This commit is contained in:
QdabuliuQ
2026-01-13 18:14:54 +08:00
committed by GitHub
parent e05aa23faa
commit 8fd30ab4a2
2 changed files with 19 additions and 2 deletions

View File

@@ -115,6 +115,23 @@ describe('Button', () => {
expect(container.querySelector('.ant-btn')).toHaveClass('ant-btn-two-chinese-chars');
});
// https://github.com/ant-design/ant-design/issues/56591
it('should preserve className when rendering two Chinese characters in child element', () => {
const { container } = render(
<Button>
<span className="custom-class" style={{ color: 'rgb(255, 0, 0)' }}>
</span>
</Button>,
);
const span = container.querySelector('span.custom-class');
expect(span).toBeTruthy();
expect(span).toHaveClass('custom-class');
expect(span).toHaveStyle({ color: 'rgb(255, 0, 0)' });
expect(span).toHaveTextContent('按 钮');
});
// https://github.com/ant-design/ant-design/issues/18118
it('should not insert space to link or text button', () => {
const wrapper1 = render(<Button type="link"></Button>);

View File

@@ -54,8 +54,8 @@ function splitCNCharsBySpace(
return cloneElement(child, (oriProps) => ({
...oriProps,
children: oriProps.children.split('').join(SPACE),
className,
style,
className: clsx(oriProps.className, className) || undefined,
style: { ...oriProps.style, ...style },
}));
}