From 25acc479f01cbeff846267f4e27029f52f11d8cb Mon Sep 17 00:00:00 2001 From: JiaQi <112228030+Yuiai01@users.noreply.github.com> Date: Thu, 13 Jul 2023 09:43:35 +0800 Subject: [PATCH] fix(Tag): renders excess content when passing only the icon (#43518) * fix: add judgment * chore: add test case --- components/tag/__tests__/index.test.tsx | 6 ++++++ components/tag/index.tsx | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/components/tag/__tests__/index.test.tsx b/components/tag/__tests__/index.test.tsx index a46d9f8cd1..81ca509ade 100644 --- a/components/tag/__tests__/index.test.tsx +++ b/components/tag/__tests__/index.test.tsx @@ -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(} />); + expect(container.querySelector('.ant-tag ')?.childElementCount).toBe(1); + }); + it('deprecated warning', () => { resetWarned(); const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); diff --git a/components/tag/index.tsx b/components/tag/index.tsx index 06a5ed1b63..d26f5d2aa1 100644 --- a/components/tag/index.tsx +++ b/components/tag/index.tsx @@ -128,7 +128,7 @@ const InternalTag: React.ForwardRefRenderFunction = ( const kids: React.ReactNode = iconNode ? ( <> {iconNode} - {children} + {children && {children}} ) : ( children