mirror of
https://github.com/ant-design/ant-design.git
synced 2026-02-09 02:49:18 +08:00
chore: add deprecated warning for Modal (#56507)
* test: add test case * chore: fix lint
This commit is contained in:
@@ -137,6 +137,8 @@ const Modal: React.FC<ModalProps> = (props) => {
|
||||
['bodyStyle', 'styles.body'],
|
||||
['maskStyle', 'styles.mask'],
|
||||
['destroyOnClose', 'destroyOnHidden'],
|
||||
['autoFocusButton', 'focusable.autoFocusButton'],
|
||||
['focusTriggerAfterClose', 'focusable.focusTriggerAfterClose'],
|
||||
].forEach(([deprecatedName, newName]) => {
|
||||
warning.deprecated(!(deprecatedName in props), deprecatedName, newName);
|
||||
});
|
||||
|
||||
@@ -422,4 +422,45 @@ describe('Modal', () => {
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('should warning when using deprecated autoFocusButton', () => {
|
||||
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||
|
||||
const Test = () => {
|
||||
const [modal, holder] = Modal.useModal();
|
||||
|
||||
React.useEffect(() => {
|
||||
modal.confirm({
|
||||
autoFocusButton: 'ok',
|
||||
content: 'Here is content of Modal',
|
||||
});
|
||||
}, []);
|
||||
|
||||
return holder;
|
||||
};
|
||||
|
||||
render(<Test />);
|
||||
|
||||
expect(errorSpy).toHaveBeenCalledWith(
|
||||
'Warning: [antd: Modal] `autoFocusButton` is deprecated. Please use `focusable.autoFocusButton` instead.',
|
||||
);
|
||||
|
||||
errorSpy.mockRestore();
|
||||
});
|
||||
|
||||
it('should warning when using deprecated focusTriggerAfterClose', () => {
|
||||
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||
|
||||
render(
|
||||
<Modal open focusTriggerAfterClose={false} getContainer={false}>
|
||||
Here is content of Modal
|
||||
</Modal>,
|
||||
);
|
||||
|
||||
expect(errorSpy).toHaveBeenCalledWith(
|
||||
'Warning: [antd: Modal] `focusTriggerAfterClose` is deprecated. Please use `focusable.focusTriggerAfterClose` instead.',
|
||||
);
|
||||
|
||||
errorSpy.mockRestore();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user