Skip to content

Number field ​

A number input formatted for the locale, with a currency and a step.

Describe the format in formatOptions, as for Intl.NumberFormat. A typed number reaches the model when the user leaves the field or presses Enter.

Installation ​

ts
import { NuiNumberField } from '@numior/kit';

Usage ​

Change the bounds, the step and the buttons of the field.

Smallest value. A lower number becomes min when the field loses focus.

Largest value. A higher number becomes max when the field loses focus.

Amount the arrow keys and plus and minus buttons change the number by. The value rounds to steps from min.

size
Changes the size of the control: sm, md or lg. The theme density shifts the height of each size.

Label of the control. Inside NuiField the field provides the label.

Hint below the control. Screen readers announce it with the control.

Error text below the control. Puts the control into the error state.

Examples ​

Limit the range ​

Set min, max and step.

From 0 to 50% in steps of 5

A number outside the range turns into the nearest bound when the user leaves the field. A value that was never edited in the field stays in the model as it was.

Show the number in another format ​

Pass locale to the field.

A field without locale follows the app language.

Accessibility ​

The field has the spinbutton role, so a screen reader announces the value with the minimum and the maximum. The plus and minus buttons are hidden from it and never take focus: the arrow keys do the same.

On iOS the decimal keypad has no minus sign, so pass inputmode="text" for negative numbers.

Keys
Action
↑
Increases the number by one step, or ten steps with Shift.
↓
Decreases the number by one step, or ten steps with Shift.
PageUp
Increases the number by ten steps.
PageDown
Decreases the number by ten steps.
Home
Sets the value to min.
End
Sets the value to max.
↵
Applies the typed number. The form still submits as usual.

API ​

Props

Name
Type
Default
Description
min
number
—
Smallest value. A lower number becomes min when the field loses focus.
max
number
—
Largest value. A higher number becomes max when the field loses focus.
step
number
1
Amount the arrow keys and plus and minus buttons change the number by. The value rounds to steps from min.
formatOptions
Intl.NumberFormatOptions
—
Number format as Intl.NumberFormat options: currency, percent, fraction digits.
locale
string
—
Locale of the number format, such as en-US. Defaults to the locale from createNuiConfig.
steppers
boolean
true
Shows the plus and minus buttons.
name
string
—
Name the number is submitted with in a form.
incrementLabel
string
—
Plus button label for screen readers. Defaults to "Increment" from the dictionary.
decrementLabel
string
—
Minus button label for screen readers. Defaults to "Decrement" from the dictionary.
id
string
—
Id of the control. Defaults to the one from NuiField or is generated automatically.
size
NuiSize
"md"
Changes the size of the control: sm, md or lg. The theme density shifts the height of each size.
disabled
boolean
—
Disables the control. Inside NuiField it defaults to the field value.
readonly
boolean
—
Blocks typing. The number can still be selected and copied.
required
boolean
—
Marks the control as required. Inside NuiField it defaults to the field value.
invalid
boolean
—
Shows the error state without a text. With error it turns on by itself.
label
string
—
Label of the control. Inside NuiField the field provides the label.
description
string
—
Hint below the control. Screen readers announce it with the control.
error
string
—
Error text below the control. Puts the control into the error state.
reserveError
boolean
false
Reserves space for the error so the form does not shift when it appears.

Models

Name
Type
Default
Description
v-model
number | null
null
Number in the field, or null when the field is empty.

Slots

Name
Slot props
Description
prefix
{}
Content before the number inside the field, such as a currency sign.
suffix
{}
Content after the number inside the field, such as a unit.

Exposed

Name
Type
Description
focus
() => void | undefined
Focuses the field.

Texts

Key
Russian
English
decrement
Уменьшить
Decrement
increment
Увеличить
Increment

Edit this page

Search

Esc