diff --git a/components/input-number/__tests__/index.test.js b/components/input-number/__tests__/index.test.js index eb276a34e6..3011856794 100644 --- a/components/input-number/__tests__/index.test.js +++ b/components/input-number/__tests__/index.test.js @@ -19,4 +19,15 @@ describe('InputNumber', () => { wrapper.find('input').simulate('blur'); expect(onChange).toHaveBeenLastCalledWith(null); }); + + it('should call onStep when press up or down button', () => { + const onStep = jest.fn(); + const wrapper = mount(); + wrapper.find('.ant-input-number-handler-up').simulate('mousedown'); + expect(onStep).toBeCalledTimes(1); + expect(onStep).toHaveBeenLastCalledWith(2, { offset: 1, type: 'up' }); + wrapper.find('.ant-input-number-handler-down').simulate('mousedown'); + expect(onStep).toBeCalledTimes(2); + expect(onStep).toHaveBeenLastCalledWith(1, { offset: 1, type: 'down' }); + }); }); diff --git a/components/input-number/index.en-US.md b/components/input-number/index.en-US.md index 8d83b88c8f..870949ef78 100644 --- a/components/input-number/index.en-US.md +++ b/components/input-number/index.en-US.md @@ -13,23 +13,24 @@ When a numeric value needs to be provided. ## API -| Property | Description | Type | Default | -| --- | --- | --- | --- | -| autoFocus | If get focus when component mounted | boolean | false | -| defaultValue | The initial value | number | - | -| disabled | If disable the input | boolean | false | -| readOnly | If readonly the input | boolean | false | -| formatter | Specifies the format of the value presented | function(value: number \| string): string | - | -| max | The max value | number | [Number.MAX_SAFE_INTEGER](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER) | -| min | The min value | number | [Number.MIN_SAFE_INTEGER](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_SAFE_INTEGER) | -| parser | Specifies the value extracted from formatter | function(string): number | - | -| precision | The precision of input value | number | - | -| decimalSeparator | Decimal separator | string | - | -| size | The height of input box | `large` \| `middle` \| `small` | - | -| step | The number to which the current value is increased or decreased. It can be an integer or decimal | number \| string | 1 | -| value | The current value | number | - | -| onChange | The callback triggered when the value is changed | function(value: number \| string) | - | -| onPressEnter | The callback function that is triggered when Enter key is pressed | function(e) | - | +| Property | Description | Type | Default | Version | +| --- | --- | --- | --- | --- | +| autoFocus | If get focus when component mounted | boolean | false | - | +| defaultValue | The initial value | number | - | - | +| disabled | If disable the input | boolean | false | - | +| readOnly | If readonly the input | boolean | false | - | +| formatter | Specifies the format of the value presented | function(value: number \| string): string | - | - | +| max | The max value | number | [Number.MAX_SAFE_INTEGER](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER) | - | +| min | The min value | number | [Number.MIN_SAFE_INTEGER](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_SAFE_INTEGER) | - | +| parser | Specifies the value extracted from formatter | function(string): number | - | - | +| precision | The precision of input value | number | - | - | +| decimalSeparator | Decimal separator | string | - | - | +| size | The height of input box | `large` \| `middle` \| `small` | - | - | +| step | The number to which the current value is increased or decreased. It can be an integer or decimal | number \| string | 1 | - | +| value | The current value | number | - | - | +| onChange | The callback triggered when the value is changed | function(value: number \| string) | - | - | +| onPressEnter | The callback function that is triggered when Enter key is pressed | function(e) | - | - | +| onStep | The callback function that is triggered when click up or down buttons | `(value: number, info: { offset: number, type: 'up' | 'down' }) => void` | - | 4.7.0 | ## Methods diff --git a/components/input-number/index.tsx b/components/input-number/index.tsx index f54bd8c315..1268349d79 100644 --- a/components/input-number/index.tsx +++ b/components/input-number/index.tsx @@ -34,6 +34,7 @@ export interface InputNumberProps id?: string; precision?: number; onPressEnter?: React.KeyboardEventHandler; + onStep?: (value: number, info: { offset: number, type: 'up' | 'down' }) => void; } const InputNumber = React.forwardRef((props, ref) => { diff --git a/components/input-number/index.zh-CN.md b/components/input-number/index.zh-CN.md index 269c4a4a1e..5766f32f3f 100644 --- a/components/input-number/index.zh-CN.md +++ b/components/input-number/index.zh-CN.md @@ -16,23 +16,24 @@ cover: https://gw.alipayobjects.com/zos/alicdn/XOS8qZ0kU/InputNumber.svg 属性如下 -| 成员 | 说明 | 类型 | 默认值 | -| --- | --- | --- | --- | -| autoFocus | 自动获取焦点 | boolean | false | -| defaultValue | 初始值 | number | - | -| disabled | 禁用 | boolean | false | -| readOnly | 只读 | boolean | false | -| formatter | 指定输入框展示值的格式 | function(value: number \| string): string | - | -| max | 最大值 | number | [Number.MAX_SAFE_INTEGER](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER) | -| min | 最小值 | number | [Number.MIN_SAFE_INTEGER](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_SAFE_INTEGER) | -| parser | 指定从 `formatter` 里转换回数字的方式,和 `formatter` 搭配使用 | function(string): number | - | -| precision | 数值精度 | number | - | -| decimalSeparator | 小数点 | string | - | -| size | 输入框大小 | `large` \| `middle` \| `small` | - | -| step | 每次改变步数,可以为小数 | number \| string | 1 | -| value | 当前值 | number | - | -| onChange | 变化回调 | function(value: number \| string) | - | -| onPressEnter | 按下回车的回调 | function(e) | - | +| 成员 | 说明 | 类型 | 默认值 | 版本 | +| --- | --- | --- | --- | --- | +| autoFocus | 自动获取焦点 | boolean | false | - | +| defaultValue | 初始值 | number | - | - | +| disabled | 禁用 | boolean | false | - | +| readOnly | 只读 | boolean | false | - | +| formatter | 指定输入框展示值的格式 | function(value: number \| string): string | - | - | +| max | 最大值 | number | [Number.MAX_SAFE_INTEGER](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER) | - | +| min | 最小值 | number | [Number.MIN_SAFE_INTEGER](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_SAFE_INTEGER) | - | +| parser | 指定从 `formatter` 里转换回数字的方式,和 `formatter` 搭配使用 | function(string): number | - | - | +| precision | 数值精度 | number | - | - | +| decimalSeparator | 小数点 | string | - | - | +| size | 输入框大小 | `large` \| `middle` \| `small` | - | - | +| step | 每次改变步数,可以为小数 | number \| string | 1 | - | +| value | 当前值 | number | - | - | +| onChange | 变化回调 | function(value: number \| string) | - | - | +| onPressEnter | 按下回车的回调 | function(e) | - | - | +| onStep | 点击上下箭头的回调 | `(value: number, info: { offset: number, type: 'up' | 'down' }) => void` | - | 4.7.0 | ## 方法 diff --git a/package.json b/package.json index 64f1af7c34..715404c82b 100644 --- a/package.json +++ b/package.json @@ -126,7 +126,7 @@ "rc-dropdown": "~3.2.0", "rc-field-form": "~1.12.0", "rc-image": "~3.2.1", - "rc-input-number": "~6.0.0", + "rc-input-number": "~6.1.0", "rc-mentions": "~1.5.0", "rc-menu": "~8.7.1", "rc-motion": "^2.2.0",