mirror of
https://github.com/ant-design/ant-design.git
synced 2025-08-06 07:56:28 +08:00
fix(Tag): renders excess content when passing only the icon (#43518)
* fix: add judgment * chore: add test case
This commit is contained in:
parent
82e5555ff3
commit
25acc479f0
@ -1,6 +1,7 @@
|
||||
import React from 'react';
|
||||
import { Simulate } from 'react-dom/test-utils';
|
||||
|
||||
import { CheckCircleOutlined } from '@ant-design/icons';
|
||||
import Tag from '..';
|
||||
import { resetWarned } from '../../_util/warning';
|
||||
|
||||
@ -135,6 +136,11 @@ describe('Tag', () => {
|
||||
expect(onClick).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should only render icon when no children', () => {
|
||||
const { container } = render(<Tag icon={<CheckCircleOutlined />} />);
|
||||
expect(container.querySelector('.ant-tag ')?.childElementCount).toBe(1);
|
||||
});
|
||||
|
||||
it('deprecated warning', () => {
|
||||
resetWarned();
|
||||
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||
|
@ -128,7 +128,7 @@ const InternalTag: React.ForwardRefRenderFunction<HTMLSpanElement, TagProps> = (
|
||||
const kids: React.ReactNode = iconNode ? (
|
||||
<>
|
||||
{iconNode}
|
||||
<span>{children}</span>
|
||||
{children && <span>{children}</span>}
|
||||
</>
|
||||
) : (
|
||||
children
|
||||
|
Loading…
Reference in New Issue
Block a user