Importimport { InputNumber } from 'antd'; |
When a numeric value needs to be provided.
Common props ref:Common props
| Property | Description | Type | Default | Version |
|---|---|---|---|---|
| The label text displayed after (on the right side of) the input field, please use Space.Compact instead | ReactNode | - | ||
| The label text displayed before (on the left side of) the input field, please use Space.Compact instead | ReactNode | - | ||
| changeOnBlur | Trigger onChange when blur. e.g. reset value in range by blur | boolean | true | 5.11.0 |
| changeOnWheel | Allows control with mouse wheel | boolean | - | 5.14.0 |
| classNames | Customize class for each semantic structure inside the component. Supports object or function. | Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string> | - | - |
| controls | Whether to show +- controls, or set custom arrow icons | boolean | { upIcon?: React.ReactNode; downIcon?: React.ReactNode; } | - | |
| decimalSeparator | Decimal separator | string | - | - |
| placeholder | Placeholder | string | - | |
| defaultValue | The initial value | number | - | - |
| disabled | If the input is disabled | boolean | false | - |
| formatter | Specifies the format of the value presented | function(value: number | string, info: { userTyping: boolean, input: string }): string | - | |
| keyboard | If keyboard behavior is enabled | boolean | true | |
| max | The max value | number | Number.MAX_SAFE_INTEGER | - |
| min | The min value | number | Number.MIN_SAFE_INTEGER | - |
| parser | Specifies the value extracted from formatter | function(string): number | - | - |
| precision | The precision of input value. Will use formatter when config of formatter | number | - | - |
| readOnly | If the input is readonly | boolean | false | - |
| status | Set validation status | 'error' | 'warning' | - | |
| styles | Customize inline style for each semantic structure inside the component. Supports object or function. | Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties> | - | - |
| prefix | The prefix icon for the Input | ReactNode | - | |
| suffix | The suffix icon for the Input | ReactNode | - | 5.20.0 |
| size | The height of input box | large | medium | small | - | - |
| step | The number to which the current value is increased or decreased. It can be an integer or decimal | number | string | 1 | - |
| stringMode | Set value as string to support high precision decimals. Will return string value by onChange | boolean | false | |
| mode | Show input or spinner | 'input' | 'spinner' | 'input' | |
| value | The current value of the component | number | - | - |
| variant | Variants of Input | outlined | borderless | filled | underlined | outlined | 5.13.0 | underlined: 5.24.0 |
| onChange | The callback triggered when the value is changed | function(value: number | string | null) | - | - |
| 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 / Keyboard / Wheel | (value: number, info: { offset: number, type: 'up' | 'down', emitter: 'handler' | 'keydown' | 'wheel' }) => void | - | |
Whether has border style, please use variant instead | boolean | true | - |
| Name | Description | Type | Version |
|---|---|---|---|
| blur() | Remove focus | - | |
| focus() | Get focus | (option?: { preventScroll?: boolean, cursor?: 'start' | 'end' | 'all' }) | cursor - 5.22.0 |
| nativeElement | The native DOM element | - | 5.17.3 |
| Token Name | Description | Type | Default Value |
|---|---|---|---|
| activeBg | Background color when the input box is activated | string | #ffffff |
| activeBorderColor | Active border color | string | #1677ff |
| activeShadow | Box-shadow when active | string | 0 0 0 2px rgba(5,145,255,0.1) |
| addonBg | Background color of addon | string | rgba(0,0,0,0.02) |
| controlWidth | Width of input | number | 90 |
| errorActiveShadow | Box-shadow when active in error status | string | 0 0 0 2px rgba(255,38,5,0.06) |
| filledHandleBg | Background color of handle in filled variant | string | #f0f0f0 |
| handleActiveBg | Active background color of handle | string | rgba(0,0,0,0.02) |
| handleBg | Background color of handle | string | #ffffff |
| handleBorderColor | Border color of handle | string | #d9d9d9 |
| handleFontSize | Icon size of control button | number | 7 |
| handleHoverColor | Hover color of handle | string | #1677ff |
| handleVisible | Handle visible | true | "auto" | auto |
| handleWidth | Width of control button | number | 22 |
| hoverBg | Background color when the input box hovers | string | #ffffff |
| hoverBorderColor | Hover border color | string | #4096ff |
| inputFontSize | Font size | number | 14 |
| inputFontSizeLG | Font size of large | number | 16 |
| inputFontSizeSM | Font size of small | number | 14 |
| paddingBlock | Vertical padding of input | number | 4 |
| paddingBlockLG | Vertical padding of large input | number | 7 |
| paddingBlockSM | Vertical padding of small input | number | 0 |
| paddingInline | Horizontal padding of input | number | 11 |
| paddingInlineLG | Horizontal padding of large input | number | 11 |
| paddingInlineSM | Horizontal padding of small input | number | 7 |
| warningActiveShadow | Box-shadow when active in warning status | string | 0 0 0 2px rgba(255,215,5,0.1) |
| Token Name | Description | Type | Default Value |
|---|---|---|---|
| colorBgContainer | Container background color, e.g: default button, input box, etc. Be sure not to confuse this with `colorBgElevated`. | string | #ffffff |
| colorBgContainerDisabled | Control the background color of container in disabled state. | string | rgba(0,0,0,0.04) |
| colorBorder | Default border color, used to separate different elements, such as: form separator, card separator, etc. | string | #d9d9d9 |
| colorBorderDisabled | Control the border color of the element in the disabled state. | string | #d9d9d9 |
| colorError | Used to represent the visual elements of the operation failure, such as the error Button, error Result component, etc. | string | #ff4d4f |
| colorErrorAffix | Control the color of form control prefix/suffix in error state. | string | #ff4d4f |
| colorErrorBg | The background color of the error state. | string | #fff2f0 |
| colorErrorBgHover | The hover state background color of the error state. | string | #fff1f0 |
| colorErrorBorderHover | The hover state border color of the error state. | string | #ffa39e |
| colorErrorText | The default state of the text in the error color. | string | #ff4d4f |
| colorFillSecondary | The second level of fill color can outline the shape of the element more clearly, such as Rate, Skeleton, etc. It can also be used as the Hover state of the third level of fill color, such as Table, etc. | string | rgba(0,0,0,0.06) |
| colorFillTertiary | The third level of fill color is used to outline the shape of the element, such as Slider, Segmented, etc. If there is no emphasis requirement, it is recommended to use the third level of fill color as the default fill color. | string | rgba(0,0,0,0.04) |
| colorIcon | Weak action. Such as `allowClear` or Alert close button | string | rgba(0,0,0,0.45) |
| colorText | Default text color which comply with W3C standards, and this color is also the darkest neutral color. | string | rgba(0,0,0,0.88) |
| colorTextDisabled | Control the color of text in disabled state. | string | rgba(0,0,0,0.25) |
| colorTextPlaceholder | Control the color of placeholder text. | string | rgba(0,0,0,0.25) |
| colorWarning | Used to represent the warning map token, such as Notification, Alert, etc. Alert or Control component(like Input) will use these map tokens. | string | #faad14 |
| colorWarningAffix | Control the color of form control prefix/suffix in warning state. | string | #faad14 |
| colorWarningBg | The background color of the warning state. | string | #fffbe6 |
| colorWarningBgHover | The hover state background color of the warning state. | string | #fff1b8 |
| colorWarningBorderHover | The hover state border color of the warning state. | string | #ffd666 |
| colorWarningText | The default state of the text in the warning color. | string | #faad14 |
| borderRadius | Border radius of base components | number | 6 |
| borderRadiusLG | LG size border radius, used in some large border radius components, such as Card, Modal and other components. | number | 8 |
| borderRadiusSM | SM size border radius, used in small size components, such as Button, Input, Select and other input components in small size | number | 4 |
| fontFamily | The font family of Ant Design prioritizes the default interface font of the system, and provides a set of alternative font libraries that are suitable for screen display to maintain the readability and readability of the font under different platforms and browsers, reflecting the friendly, stable and professional characteristics. | string | -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji' |
| fontSize | The most widely used font size in the design system, from which the text gradient will be derived. | number | 14 |
| lineHeight | Line height of text. | number | 1.5714285714285714 |
| lineHeightLG | Line height of large text. | number | 1.5 |
| lineType | Border style of base components | string | solid |
| lineWidth | Border width of base components | number | 1 |
| motionDurationMid | Motion speed, medium speed. Used for medium element animation interaction. | string | 0.2s |
| paddingXXS | Control the extra extra small padding of the element. | number | 4 |
Per issues #21158, #17344, #9421, and documentation about inputs, it appears this community does not support native inclusion of the type="number" in the <Input /> attributes, so please feel free to include it as needed, and be aware that it is heavily suggested that server side validation be utilized, as client side validation can be edited by power users.
value can exceed min or max in control?Developer handle data by their own in control. It will make data out of sync if InputNumber changes display value. It also cause potential data issues when use in form.
min or max which makes value out of range will not trigger onChange?onChange is user trigger event. Auto-triggering would prevent form libraries from detecting the data modification source.
onBlur or other event can not get correct value?InputNumber's value is wrapped by internal logic. The event.target.value you get from onBlur or other event is the DOM element's value instead of the actual value of InputNumber. For example, if you change the display format through formatter or decimalSeparator, you will get the formatted string in the DOM. You should always get the current value through onChange.
changeOnWheel unable to control whether the mouse scroll wheel changes value?The use of the
typeattribute is deprecated
The InputNumber component allows you to use all the attributes of the input element and ultimately pass them to the input element, This attribute will also be added to the input element when you pass in type='number', which will activate native behavior (allowing the mouse wheel to change the value), As a result changeOnWheel cannot control whether the mouse wheel changes the value.