Skip to content

Commit

Permalink
feat: retire deprecated api
Browse files Browse the repository at this point in the history
  • Loading branch information
aojunhao123 committed Jan 14, 2025
1 parent 69ddd7f commit 70931af
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 66 deletions.
50 changes: 1 addition & 49 deletions components/tag/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';
import { CheckCircleOutlined, CloseCircleOutlined } from '@ant-design/icons';

import Tag from '..';
import { resetWarned } from '../../_util/warning';
import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest';
import { act, fireEvent, render } from '../../../tests/utils';
Expand Down Expand Up @@ -120,54 +119,7 @@ describe('Tag', () => {
expect(container.querySelector('.ant-tag ')?.childElementCount).toBe(1);
});

it('deprecated warning', () => {
resetWarned();
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});

const { container } = render(<Tag visible={false} />);
expect(errSpy).toHaveBeenCalledWith(
'Warning: [antd: Tag] `visible` is deprecated. Please use `visible && <Tag />` instead.',
);
expect(container.querySelector('.ant-tag-hidden')).toBeTruthy();

errSpy.mockRestore();
});

describe('visibility', () => {
it('can be controlled by visible with visible as initial value', () => {
const { container, rerender } = render(<Tag visible />);
expect(container.querySelector('.ant-tag-hidden')).toBeFalsy();

rerender(<Tag visible={false} />);
act(() => {
jest.runAllTimers();
});
expect(container.querySelector('.ant-tag-hidden')).toBeTruthy();

rerender(<Tag visible />);
act(() => {
jest.runAllTimers();
});
expect(container.querySelector('.ant-tag-hidden')).toBeFalsy();
});

it('can be controlled by visible with hidden as initial value', () => {
const { container, rerender } = render(<Tag visible={false} />);
expect(container.querySelector('.ant-tag-hidden')).toBeTruthy();

rerender(<Tag visible />);
act(() => {
jest.runAllTimers();
});
expect(container.querySelector('.ant-tag-hidden')).toBeFalsy();

rerender(<Tag visible={false} />);
act(() => {
jest.runAllTimers();
});
expect(container.querySelector('.ant-tag-hidden')).toBeTruthy();
});

describe('disabled', () => {
it('should not trigger onClick when disabled', () => {
const onClick = jest.fn();
const { container } = render(<Tag disabled onClick={onClick} />);
Expand Down
17 changes: 0 additions & 17 deletions components/tag/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type { ClosableType } from '../_util/hooks/useClosable';
import useClosable, { pickClosable } from '../_util/hooks/useClosable';
import { replaceElement } from '../_util/reactNode';
import type { LiteralUnion } from '../_util/type';
import { devUseWarning } from '../_util/warning';
import Wave from '../_util/wave';
import { ConfigContext } from '../config-provider';
import CheckableTag from './CheckableTag';
Expand All @@ -27,8 +26,6 @@ export interface TagProps extends React.HTMLAttributes<HTMLSpanElement> {
/** Advised to use closeIcon instead. */
closable?: ClosableType;
closeIcon?: React.ReactNode;
/** @deprecated `visible` will be removed in next major version. */
visible?: boolean;
onClose?: (e: React.MouseEvent<HTMLElement>) => void;
style?: React.CSSProperties;
icon?: React.ReactNode;
Expand All @@ -50,7 +47,6 @@ const InternalTag = React.forwardRef<HTMLSpanElement | HTMLAnchorElement, TagPro
color,
onClose,
bordered = true,
visible: deprecatedVisible,
disabled: customDisabled,
href,
target,
Expand All @@ -66,19 +62,6 @@ const InternalTag = React.forwardRef<HTMLSpanElement | HTMLAnchorElement, TagPro

const domProps = omit(props, ['closeIcon', 'closable']);

// Warning for deprecated usage
if (process.env.NODE_ENV !== 'production') {
const warning = devUseWarning('Tag');

warning.deprecated(!('visible' in tagProps), 'visible', 'visible && <Tag />');
}

React.useEffect(() => {
if (deprecatedVisible !== undefined) {
setVisible(deprecatedVisible!);
}
}, [deprecatedVisible]);

const isPreset = isPresetColor(color);
const isStatus = isPresetStatusColor(color);
const isInternalColor = isPreset || isStatus;
Expand Down

0 comments on commit 70931af

Please sign in to comment.