chore: add deprecated warning for Modal (#56507)

* test: add test case

* chore: fix lint
This commit is contained in:
二货爱吃白萝卜
2026-01-06 15:12:39 +08:00
committed by GitHub
parent 0cdfaf578a
commit d7aac85735
2 changed files with 43 additions and 0 deletions

View File

@@ -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);
});

View File

@@ -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();
});
});