chore: InputNumber add usage tips (#49648)

This commit is contained in:
Wanpan 2024-06-28 23:19:58 +08:00 committed by GitHub
parent abe483d7d0
commit c4928586af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 5 deletions

View File

@ -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(<InputNumber bordered={false} />);
expect(errorSpy).toHaveBeenCalledWith(
const { container } = render(<InputNumber bordered={false} type="number" changeOnWheel />);
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();
});

View File

@ -42,8 +42,13 @@ export interface InputNumberProps<T extends ValueType = ValueType>
const InputNumber = React.forwardRef<HTMLInputElement, InputNumberProps>((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);