Browse Source
fix(Tag): renders excess content when passing only the icon (#43518)
* fix: add judgment
* chore: add test case
pull/43277/head
JiaQi
1 year ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
7 additions and
1 deletions
-
components/tag/__tests__/index.test.tsx
-
components/tag/index.tsx
|
@ -1,6 +1,7 @@ |
|
|
import React from 'react'; |
|
|
import React from 'react'; |
|
|
import { Simulate } from 'react-dom/test-utils'; |
|
|
import { Simulate } from 'react-dom/test-utils'; |
|
|
|
|
|
|
|
|
|
|
|
import { CheckCircleOutlined } from '@ant-design/icons'; |
|
|
import Tag from '..'; |
|
|
import Tag from '..'; |
|
|
import { resetWarned } from '../../_util/warning'; |
|
|
import { resetWarned } from '../../_util/warning'; |
|
|
|
|
|
|
|
@ -135,6 +136,11 @@ describe('Tag', () => { |
|
|
expect(onClick).not.toHaveBeenCalled(); |
|
|
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', () => { |
|
|
it('deprecated warning', () => { |
|
|
resetWarned(); |
|
|
resetWarned(); |
|
|
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); |
|
|
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); |
|
|
|
@ -128,7 +128,7 @@ const InternalTag: React.ForwardRefRenderFunction<HTMLSpanElement, TagProps> = ( |
|
|
const kids: React.ReactNode = iconNode ? ( |
|
|
const kids: React.ReactNode = iconNode ? ( |
|
|
<> |
|
|
<> |
|
|
{iconNode} |
|
|
{iconNode} |
|
|
<span>{children}</span> |
|
|
{children && <span>{children}</span>} |
|
|
</> |
|
|
</> |
|
|
) : ( |
|
|
) : ( |
|
|
children |
|
|
children |
|
|