InputNumber is an input component to provide numerical input.
import InputNumber from 'primevue/inputnumber';
InputNumber is used with the v-model property for two-way value binding.
<InputNumber v-model="value1" inputId="integeronly" fluid />
<InputNumber v-model="value2" inputId="withoutgrouping" :useGrouping="false" fluid />
<InputNumber v-model="value3" inputId="minmaxfraction" :minFractionDigits="2" :maxFractionDigits="5" fluid />
<InputNumber v-model="value4" inputId="minmax" :min="0" :max="100" fluid />
InputNumber integrates seamlessly with the PrimeVue Forms library.
<Form v-slot="$form" :resolver="resolver" :initialValues="initialValues" @submit="onFormSubmit" class="flex flex-col gap-4 w-full sm:w-56">
<div class="flex flex-col gap-1">
<InputNumber name="amount" fluid />
<Message v-if="$form.amount?.invalid" severity="error" size="small" variant="simple">{{ $form.amount.error?.message }}</Message>
</div>
<Button type="submit" severity="secondary" label="Submit" />
</Form>
Localization information such as grouping and decimal symbols are defined with the locale property which defaults to the user locale.
<InputNumber v-model="value1" inputId="locale-user" :minFractionDigits="2" fluid />
<InputNumber v-model="value2" inputId="locale-us" locale="en-US" :minFractionDigits="2" fluid />
<InputNumber v-model="value3" inputId="locale-german" locale="de-DE" :minFractionDigits="2" fluid />
<InputNumber v-model="value4" inputId="locale-indian" locale="en-IN" :minFractionDigits="2" fluid />
Monetary values are enabled by setting mode property as currency. In this setting, currency property also needs to be defined using ISO 4217 standard such as "USD" for the US dollar.
<InputNumber v-model="value1" inputId="currency-us" mode="currency" currency="USD" locale="en-US" fluid />
<InputNumber v-model="value2" inputId="currency-germany" mode="currency" currency="EUR" locale="de-DE" />
<InputNumber v-model="value3" inputId="currency-india" mode="currency" currency="INR" currencyDisplay="code" locale="en-IN" fluid />
<InputNumber v-model="value4" inputId="currency-japan" mode="currency" currency="JPY" locale="jp-JP" fluid />
Custom texts e.g. units can be placed before or after the input section with the prefix and suffix properties.
<InputNumber v-model="value1" inputId="mile" suffix=" mi" fluid />
<InputNumber v-model="value2" inputId="percent" prefix="%" fluid />
<InputNumber v-model="value3" inputId="expiry" prefix="Expires in " suffix=" days" fluid />
<InputNumber v-model="value4" inputId="temperature" prefix="↑ " suffix="℃" :min="0" :max="40" fluid />
Spinner buttons are enabled using the showButtons property and layout is defined with the buttonLayout.
<InputNumber v-model="value1" inputId="stacked-buttons" showButtons mode="currency" currency="USD" fluid />
<InputNumber v-model="value2" inputId="minmax-buttons" mode="decimal" showButtons :min="0" :max="100" fluid />
<InputNumber v-model="value3" inputId="horizontal-buttons" showButtons buttonLayout="horizontal" :step="0.25" mode="currency" currency="EUR" fluid>
<template #incrementbuttonicon>
<span class="pi pi-plus" />
</template>
<template #decrementbuttonicon>
<span class="pi pi-minus" />
</template>
</InputNumber>
Buttons can also placed vertically by setting buttonLayout as vertical.
<InputNumber v-model="value" showButtons buttonLayout="vertical" style="width: 3rem" :min="0" :max="99">
<template #incrementbuttonicon>
<span class="pi pi-plus" />
</template>
<template #decrementbuttonicon>
<span class="pi pi-minus" />
</template>
</InputNumber>
Specify the variant property as filled to display the component with a higher visual emphasis than the default outlined style.
<InputNumber v-model="value" variant="filled" />
A floating label appears on top of the input field when focused. Visit FloatLabel documentation for more information.
<FloatLabel>
<InputNumber v-model="value1" inputId="over_label" mode="currency" currency="USD" locale="en-US" />
<label for="over_label">Over Label</label>
</FloatLabel>
<FloatLabel variant="in">
<InputNumber v-model="value2" inputId="in_label" mode="currency" currency="USD" locale="en-US" variant="filled" />
<label for="in_label">In Label</label>
</FloatLabel>
<FloatLabel variant="on">
<InputNumber v-model="value3" inputId="on_label" mode="currency" currency="USD" locale="en-US" />
<label for="on_label">On Label</label>
</FloatLabel>
IftaLabel is used to create infield top aligned labels. Visit IftaLabel documentation for more information.
<IftaLabel>
<InputNumber v-model="value" inputId="price_input" mode="currency" currency="USD" locale="en-US" variant="filled" />
<label for="price_input">Price</label>
</IftaLabel>
InputNumber provides small and large sizes as alternatives to the base.
<InputNumber v-model="value1" size="small" placeholder="Small" mode="currency" currency="USD" locale="en-US" />
<InputNumber v-model="value2" placeholder="Normal" mode="currency" currency="USD" locale="en-US" />
<InputNumber v-model="value3" size="large" placeholder="Large" mode="currency" currency="USD" locale="en-US" />
Invalid state is displayed using the invalid prop to indicate a failed validation. You can use this style when integrating with form validation libraries.
<InputNumber v-model="value1" :invalid="value1 === null" mode="decimal" :minFractionDigits="2" placeholder="Amount" />
<InputNumber v-model="value2" :invalid="value2 === null" mode="decimal" :minFractionDigits="2" variant="filled" placeholder="Amount" />
When disabled is present, the element cannot be edited and focused.
<InputNumber v-model="value" disabled prefix="%" />
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. |
API defines helper props, events and others for the PrimeVue InputNumber module.
InputNumber is an input component to provide numerical input.
Defines valid properties in InputNumber component.
Defines valid emits in InputNumber component.
name | parameters | returnType | description | |
---|---|---|---|---|
update:modelValue | value: number | void | Emitted when the value changes. | |
value-change | value: number | void | Emitted when the value changes in uncontrolled mode. | |
input | event: InputNumberInputEvent | void | Callback to invoke when the value is entered. | |
focus | event: Event | void | Callback to invoke on focus of input field. | |
blur | event: InputNumberBlurEvent | void | Callback to invoke on blur of input field. |
Defines valid slots in InputNumber component.
Defines the custom events used by the component's emit.
Custom input event.
See input
name | type | description |
---|---|---|
originalEvent | Event | Browser event |
value | undefined | string | number | New value |
formattedValue | string | currentValue |
Custom blur event.
See blur
Defines the custom interfaces used by the module.
Custom passthrough(pt) option method.
name | type | default | description |
---|---|---|---|
instance | any | null | Defines instance. |
props | InputNumberProps | null | Defines valid properties. |
state | InputNumberState | null | Defines current inline state. |
parent | any | null | Defines parent instance. |
global | undefined | object | null | Defines passthrough(pt) options in global config. |
Custom shared passthrough(pt) option method.
name | type | default | description |
---|---|---|---|
props | InputNumberProps | null | Defines valid properties. |
state | InputNumberState | null | Defines current inline state. |
Custom passthrough(pt) options.
name | type | default | description |
---|---|---|---|
root | InputNumberPassThroughOptionType<T> | null | Used to pass attributes to the root's DOM element. |
pcInputText | any | null | Used to pass attributes to the InputText component. |
buttonGroup | InputNumberPassThroughOptionType<T> | null | Used to pass attributes to the button group's DOM element. |
incrementButton | InputNumberPassThroughOptionType<T> | null | Used to pass attributes to the increment button's DOM element. |
incrementIcon | InputNumberPassThroughOptionType<T> | null | Used to pass attributes to the increment icon's DOM element. |
decrementButton | InputNumberPassThroughOptionType<T> | null | Used to pass attributes to the decrement button's DOM element. |
decrementIcon | InputNumberPassThroughOptionType<T> | null | Used to pass attributes to the decrement icon's DOM element. |
hooks | any | null | Used to manage all lifecycle hooks. |
Custom passthrough attributes for each DOM elements
Defines current inline state in InputNumber component.
name | type | default | description |
---|---|---|---|
d_modelValue | number | null | Current value state as a number. |
d_value | number | null | Current value state as a number. |
focused | boolean | false | Current focused state as a boolean. |
Defines valid listeners in InputNumber component.
name | type | default | description |
---|---|---|---|
onMousedown | Function | null | |
onMouseup | Function | null | |
onMouseleave | Function | null | |
onKeydown | Function | null | |
onKeyup | Function | null |
Defines the custom types used by the module.
values |
---|
"ceil" | "floor" | "expand" | "trunc" | "halfCeil" | "halfFloor" | "halfExpand" | "halfTrunc" | "halfEven" |
values |
---|
InputNumberPassThroughAttributes | (options: InputNumberPassThroughMethodOptions) => undefined | string | null | undefined |
values |
---|
EmitFn<InputNumberEmitsOptions> |