import InputNumber from 'primevue/inputnumber';
<script src="https://unpkg.com/primevue@^3/core/core.min.js"></script>
InputNumber is used with the standard v-model directive. Component always provides a number type although formatting on the input is a string.
<InputNumber v-model="value" />
Format is defined using the mode property, "decimal" is the default value allowing only integers when there is no other configuration.
<InputNumber v-model="value" mode="decimal" />
Fractions are configured with the minFractionDigits property. Optionally maxFractionDigits can be used to defined a boundary for the maximum digits.
<InputNumber v-model="value1" mode="decimal" :minFractionDigits="2" />
<InputNumber v-model="value2" mode="decimal" :minFractionDigits="2" :maxFractionDigits="2" />
locale option is available to set the localization information such as grouping and decimal symbols where default value is the browser locale. Locales are defined per BCP Language Tag.
User Locale
<InputNumber v-model="value1" mode="decimal" :minFractionDigits="2" />
United State Locale
<InputNumber v-model="value2" mode="decimal" locale="en-US" :minFractionDigits="2" />
German Locale
<InputNumber v-model="value3" mode="decimal" locale="de-DE" :minFractionDigits="2" />
Indian Locale
<InputNumber v-model="value4" mode="decimal" locale="en-IN" :minFractionDigits="2" />
Currency formatting is specified by setting the mode option to currency and currency property. In addition currencyDisplay option allows how the currency is displayed, valid values are "symbol" (default) or "code".
United States
<InputNumber v-model="value1" mode="currency" currency="USD" locale="en-US" />
Germany
<InputNumber v-model="value2" mode="currency" currency="EUR" locale="de-DE" />
India
<InputNumber v-model="value3" mode="currency" currency="INR" currencyDisplay="code" locale="en-IN" />
Japan
<InputNumber v-model="value4" mode="currency" currency="JPY" locale="jp-JP" />
Custom texts e.g. units can be placed before or after the input section with the prefix and suffix properties.
Mile
<InputNumber v-model="value1" suffix=" mi" />
Percent
<InputNumber v-model="value2" prefix="%" />
Expiry
<InputNumber v-model="value3" prefix="Expires in " suffix=" days" />
Temperature
<InputNumber v-model="value4" prefix="↑ " suffix="℃" :min="0" :max="40" />
Spinner buttons is enabled using the showButtons options and layout is defined with the buttonLayout. Default value is "stacked" whereas "horizontal" and "stacked" are alternatives. Note that even there are no buttons, up and down arrow keys can be used to spin the values with keyboard.
Stacked
<InputNumber v-model="value1" showButtons mode="currency" currency="USD" />
Horizontal
<InputNumber v-model="value2" showButtons buttonLayout="horizontal"
decrementButtonClass="p-button-danger" incrementButtonClass="p-button-success" incrementButtonIcon="pi pi-plus" decrementButtonIcon="pi pi-minus" mode="currency" currency="EUR" />
Vertical
<InputNumber v-model="value3" mode="decimal" showButtons buttonLayout="vertical"
decrementButtonClass="p-button-secondary" incrementButtonClass="p-button-secondary" incrementButtonIcon="pi pi-plus" decrementButtonIcon="pi pi-minus" />
Step factor is 1 by default and can be customized with step option.
<InputNumber v-model="value" :step="0.25" />
Value to be entered can be restricted by configuring the min and max options.
<InputNumber v-model="value" :min="0" :max="100" />
InputNumber passes any valid attribute to the underlying input element.
Name | Type | Default | Description |
---|---|---|---|
modelValue | number | null | Value of the component. |
format | boolean | true | Whether to format the value. |
showButtons | boolean | false | Displays spinner buttons. |
buttonLayout | string | stacked | Layout of the buttons, valid values are "stacked" (default), "horizontal" and "vertical". |
incrementButtonClass | string | null | Style class of the increment button. |
decrementButtonClass | string | null | Style class of the decrement button. |
incrementButtonIcon | string | pi pi-angle-up | Style class of the increment button. |
decrementButtonIcon | string | pi pi-angle-down | Style class of the decrement button. |
locale | string | null | Locale to be used in formatting. |
localeMatcher | string | best fit | The locale matching algorithm to use. Possible values are "lookup" and "best fit"; the default is "best fit". See Locale Negotation for details. |
mode | string | decimal | Defines the behavior of the component, valid values are "decimal" and "currency". |
prefix | string | null | Text to display before the value. |
suffix | string | decimal | Text to display after the value. |
currency | string | null | The currency to use in currency formatting. Possible values are the ISO 4217 currency codes, such as "USD" for the US dollar, "EUR" for the euro, or "CNY" for the Chinese RMB. There is no default value; if the style is "currency", the currency property must be provided. |
currencyDisplay | string | symbol | How to display the currency in currency formatting. Possible values are "symbol" to use a localized currency symbol such as €, "code" to use the ISO currency code, "name" to use a localized currency name such as "dollar"; the default is "symbol". |
useGrouping | boolean | true | Whether to use grouping separators, such as thousands separators or thousand/lakh/crore separators. |
minFractionDigits | number | null | The minimum number of fraction digits to use. Possible values are from 0 to 20; the default for plain number and percent formatting is 0; the default for currency formatting is the number of minor unit digits provided by the ISO 4217 currency code list (2 if the list doesn't provide that information). |
maxFractionDigits | number | null | The maximum number of fraction digits to use. Possible values are from 0 to 20; the default for plain number formatting is the larger of minimumFractionDigits and 3; the default for currency formatting is the larger of minimumFractionDigits and the number of minor unit digits provided by the ISO 4217 currency code list (2 if the list doesn't provide that information). |
min | number | null | Mininum boundary value. |
max | number | null | Maximum boundary value. |
step | number | 1 | Step factor to increment/decrement the value. |
allowEmpty | boolean | true | Determines whether the input field is empty. |
disabled | boolean | false | When present, it specifies that the element should be disabled. |
readonly | boolean | false | When present, it specifies that an input field is read-only. |
placeholder | string | null | Placeholder text for the input. |
inputId | string | null | Style class of the component input field. |
inputStyle | any | null | Inline style of the input field. |
inputClass | string | null | Style class of the input field. |
inputProps | object | null | Uses to pass all properties of the HTMLInputElement to the focusable input element inside the component. |
incrementButtonProps | object | null | Uses to pass all properties of the HTMLButtonElement to increment button inside the component. |
decrementButtonProps | object | null | Uses to pass all properties of the HTMLButtonElement to decrement button inside the component. |
Name | Parameters | Description |
---|---|---|
getFormatter | - | Returns Intl.NumberFormat object. |
Any valid event such as focus and blur are passed to the underlying input element. Following are the additional events to configure the component.
Name | Parameters | Description |
---|---|---|
input |
event.originalEvent: Browser event event.value: New value |
Callback to invoke when the value is entered. |
focus | event: Focus event | Callback to invoke on focus of input field. |
blur |
event.originalEvent: Blur event event.value: Input value |
Callback to invoke on blur of input field. |
Following is the list of structural style classes, for theming classes visit
Name | Element |
---|---|
p-inputnumber | Container element |
p-inputnumber-stacked | Container element with stacked buttons. |
p-inputnumber-horizontal | Container element with horizontal buttons. |
p-inputnumber-vertical | Container element with vertical buttons. |
p-inputnumber-input | Input element |
p-inputnumber-button | Input element |
p-inputnumber-button-up | Increment button |
p-inputnumber-button-down | Decrement button |
p-inputnumber-button-icon | Button icon |
Value to describe the component can either be provided via label tag combined with inputId prop or using aria-labelledby, aria-label props. The input element uses spinbutton role in addition to the aria-valuemin, aria-valuemax and aria-valuenow attributes.
<label for="price">Price</label>
<InputNumber inputId="price" />
<span id="label_number">Number</span>
<InputNumber aria-labelledby="label_number" />
<InputNumber aria-label="Number" />
Key | Function |
---|---|
tab | Moves focus to the input. |
up arrow | Increments the value. |
down arrow | Decrements the value. |
home | Set the minimum value if provided. |
end | Set the maximum value if provided. |
None.