Input · InputNumber
InputNumber
Through the mouse or keyboard, input the value in the range. Unlike Input, it has a stepper operation area for digital scenes, and it can display more complex content formats when used with Parser.
When to Use
When you need to get a standard value.
Demos
How to import
Basic Input Box
Inner Buttons
With
innerButtons
, you can hide the buttons on the right into the interior, which will only be displayed when hover occursSet
hidebuttons
to true
to hide the buttons completelySize
Custom Display Format and Resolution
A pair of methods forformatter
andparser
, which generally need to be set at the same time, otherwise the value cannot be resolved correctly.
Can Only Enter Numbers
With formatter and onNumberChange(>=v1.9.0), a pure digital input box can be implemented.
Currency Display
Version 2.77.0 supports currency display. In internationalization mode, enable currency={true} and the component will automatically display the corresponding currency type according to localeCode. (Note that the component key value needs to be updated after switching the language type)
You can also specify the currency to be displayed by manually passing localeCode and currency.
Supports three display modes: symbol, code, and name. It is controlled by the currencyDisplay property. The currency symbol is displayed by default. Set showCurrencySymbol to false to hide the display of currency symbol/code/name
Hide the display of currency symbols/codes/names, and display the currency symbol through the prefix/suffix
API Reference
Properties | Instructions | type | Default | Version |
---|---|---|---|---|
autofocus | Automatic access to focus | boolean | false | |
className | class name of InputNumber | string | - | |
clearIcon | Can be used to customize the clear button, valid when showClear is true | ReactNode | 2.25.0 | |
currency | Currency type. In international mode, currency={true} is enabled. The component will automatically display the corresponding currency type according to the locale. You can also manually pass in localeCode and currency to specify the currency type to display. The optional values of currency are CNY ,EUR ,USD , etc. | boolean|string | false | 2.77.0 |
currencyDisplay | Currency display method. Optional values: symbol, code, name | string | symbol | 2.77.0 |
defaultValue | Default | number | ||
disabled | Disabled status | boolean | false | |
formatter | Specifies the format of the input box to display the value | (value: number|string) => string | - | |
hideButtons | Hide the "up/down" button when passing true | boolean | false | 1.0.0 |
innerButtons | Show the "up/down" button in input box when passing true | boolean | false | 1.5.0 |
keepFocus | Keep the input box focused when you click the button | boolean | false | 1.10.0 |
localeCode | Used to specify the country code in currency mode. Optional values include zh-CN , en-US , en-GB , ja-JP , ko-KR , ar , vi-VN , ru-RU , id-ID , ms-MY , th-TH , tr-TR , pt-BR , zh-TW , es , de , it , fr , ro , sv-SE , pl-PL , nl-NL , etc. | string | - | 2.77.0 |
max | Limit maximum value | number | Infinity | |
min | Limit minimum value | number | -Infinity | |
parser | Specifies how to convert back number string from formatter and use them in conjunction with formatter | (value: string) => string | - | |
precision | Numerical precision | number | - | |
prefix | Prefix content | string|ReactNode | ||
pressInterval | How often will the click event be triggered when the button is long pressed, in milliseconds | number | 250 | |
pressTimeout | When the button is long pressed, how long will the click event be triggered after the delay, in milliseconds | number | 250 | |
preventScroll | Indicates whether the browser should scroll the document to display the newly focused element, acting on the focus method inside the component, excluding the component passed in by the user | boolean | ||
shiftStep | Step size for pressing the shift key, it can be a decimal. The default value was adjusted from 1 to 10 in v2.13 | number | 10 | 1.5.0 |
showClear | Do you show the clear button? | boolean | false | 0.35.0 |
showCurrencySymbol | Whether to display the currency symbol/code/name, only valid in currency mode | boolean | true | 2.77.0 |
size | Enter box size, optional value: "default"|"small"|"large" | string | 'default' | |
step | Each time you change the number of steps, it can be a decimal. | number | 1 | |
style | Inline style of InputNumber | CSSProperties | - | |
suffix | Custom suffix | ReactNode | ||
value | Current value | number | ||
onBlur | Callback when focus is lost | (e: domEvent) => void | () => {} | 1.0.0 |
onChange | Change callback | (value: number|string) => void | - | |
onFocus | Callback when focus is obtained | (e: domEvent) => void | () => {} | 1.0.0 |
onNumberChange | Number change callback | (value: number) => void | - | 1.9.0 |
Methods
Some internal methods provided by InputNumber can be accessed through ref:
Name | Description |
---|---|
blur() | Move the focus. |
focus() | Get the focus. |
Accessibility
ARIA
- InputNumber has
spinbutton
role - spinbutton uses
aria-valuenow
for current value,aria-valuemax
for acceptable maximum value, andaria-valuemin
for acceptable minimum value - When InputNumber is used in Form, the value of the input box's
aria-labeledby
reference is Field label
Keyboard and Focus
- InputNumber can get focus, keyboard users can use
Tab
andShift + Tab
to switch focus (Increase and decrease buttons are not focusable) - Keyboard users can press up key ⬆️ or down key ⬇️ and the input value will increase or decrease by
step
(default is 1) - Hold down Shift + Up ⬆️ or Down ⬇️ , the input value will increase or decrease by
shiftStep
(default is 10)