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
parent
commit
25acc479f0
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      components/tag/__tests__/index.test.tsx
  2. 2
      components/tag/index.tsx

6
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(<Tag icon={<CheckCircleOutlined />} />);
expect(container.querySelector('.ant-tag ')?.childElementCount).toBe(1);
});
it('deprecated warning', () => {
resetWarned();
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});

2
components/tag/index.tsx

@ -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…
Cancel
Save