mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-11-30 02:59:04 +08:00
feat: add waring for props#iconType in component Alert (#18046)
This commit is contained in:
parent
b5e13b2541
commit
6841e059b7
@ -49,4 +49,19 @@ describe('Alert', () => {
|
||||
expect(input.getAttribute('role')).toBe('status');
|
||||
});
|
||||
});
|
||||
|
||||
it('warning for props#iconType', () => {
|
||||
const warnSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||
mount(
|
||||
<Alert
|
||||
message="Warning Text Warning Text Warning TextW arning Text Warning Text Warning TextWarning Text"
|
||||
type="warning"
|
||||
iconType="up"
|
||||
/>,
|
||||
);
|
||||
expect(warnSpy).toHaveBeenCalledWith(
|
||||
'Warning: [antd: Alert] `iconType` is deprecated. Please use `icon` instead.',
|
||||
);
|
||||
warnSpy.mockRestore();
|
||||
});
|
||||
});
|
||||
|
@ -5,6 +5,7 @@ import Icon, { ThemeType } from '../icon';
|
||||
import classNames from 'classnames';
|
||||
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
|
||||
import getDataOrAriaProps from '../_util/getDataOrAriaProps';
|
||||
import warning from '../_util/warning';
|
||||
|
||||
function noop() {}
|
||||
|
||||
@ -41,10 +42,20 @@ export interface AlertState {
|
||||
}
|
||||
|
||||
export default class Alert extends React.Component<AlertProps, AlertState> {
|
||||
state: AlertState = {
|
||||
closing: true,
|
||||
closed: false,
|
||||
};
|
||||
constructor(props: AlertProps) {
|
||||
super(props);
|
||||
|
||||
warning(
|
||||
!('iconType' in props),
|
||||
'Alert',
|
||||
'`iconType` is deprecated. Please use `icon` instead.',
|
||||
);
|
||||
|
||||
this.state = {
|
||||
closing: true,
|
||||
closed: false,
|
||||
};
|
||||
}
|
||||
|
||||
handleClose = (e: React.MouseEvent<HTMLAnchorElement>) => {
|
||||
e.preventDefault();
|
||||
@ -89,8 +100,6 @@ export default class Alert extends React.Component<AlertProps, AlertState> {
|
||||
type = banner && type === undefined ? 'warning' : type || 'info';
|
||||
|
||||
let iconTheme: ThemeType = 'filled';
|
||||
// should we give a warning?
|
||||
// warning(!iconType, `The property 'iconType' is deprecated. Use the property 'icon' instead.`);
|
||||
if (!iconType) {
|
||||
switch (type) {
|
||||
case 'success':
|
||||
|
Loading…
Reference in New Issue
Block a user