From c4928586af855596b3f298f5c300405c649b9991 Mon Sep 17 00:00:00 2001 From: Wanpan Date: Fri, 28 Jun 2024 23:19:58 +0800 Subject: [PATCH] chore: InputNumber add usage tips (#49648) --- components/input-number/__tests__/index.test.tsx | 12 +++++++++--- components/input-number/index.tsx | 9 +++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/components/input-number/__tests__/index.test.tsx b/components/input-number/__tests__/index.test.tsx index f6494c21cd..5e51036ac1 100644 --- a/components/input-number/__tests__/index.test.tsx +++ b/components/input-number/__tests__/index.test.tsx @@ -98,12 +98,18 @@ describe('InputNumber', () => { ).toBe(true); }); - it('deprecate bordered', () => { + it('Deprecation and usage tips', () => { const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); - const { container } = render(); - expect(errorSpy).toHaveBeenCalledWith( + const { container } = render(); + expect(errorSpy).toHaveBeenNthCalledWith( + 1, 'Warning: [antd: InputNumber] `bordered` is deprecated. Please use `variant` instead.', ); + expect(errorSpy).toHaveBeenNthCalledWith( + 2, + 'Warning: [antd: InputNumber] When `type=number` is used together with `changeOnWheel`, changeOnWheel may not work properly. Please delete `type=number` if it is not necessary.', + ); + expect(container.querySelector('.ant-input-number-borderless')).toBeTruthy(); errorSpy.mockRestore(); }); diff --git a/components/input-number/index.tsx b/components/input-number/index.tsx index 9733bda5c1..a6407222d7 100644 --- a/components/input-number/index.tsx +++ b/components/input-number/index.tsx @@ -42,8 +42,13 @@ export interface InputNumberProps const InputNumber = React.forwardRef((props, ref) => { if (process.env.NODE_ENV !== 'production') { - const { deprecated } = devUseWarning('InputNumber'); - deprecated(!('bordered' in props), 'bordered', 'variant'); + const typeWarning = devUseWarning('InputNumber'); + typeWarning.deprecated(!('bordered' in props), 'bordered', 'variant'); + typeWarning( + !(props.type === 'number' && props.changeOnWheel), + 'usage', + 'When `type=number` is used together with `changeOnWheel`, changeOnWheel may not work properly. Please delete `type=number` if it is not necessary.', + ); } const { getPrefixCls, direction } = React.useContext(ConfigContext);