Create

Form

Number Field

New
Copy page View as Markdown Open in ChatGPT Open in Claude

A numeric input with buttons to decrease and increase the value.

Usage#

app.component.ts
import { WdsNumberFieldComponent } from '@wds/angular/number-field';

Name the field with a wds-field-label in a wds-field (or label). The value is a number, or null when the field is empty; it is submitted under name as a plain number, whatever the format.

Examples#

Default#

The buttons change the value by step and stop at min and max. Holding a button repeats the step.

Quantity

Step#

step sets the change of the buttons and arrow keys; typed values snap to it after a button or key.

Rating Seats In packs of 5.

Format#

format-options takes Intl.NumberFormat options as JSON (or an object as the formatOptions property): a currency, a percentage (the value is a fraction: 0.15 is 15%) or a unit. The value stays a plain number.

Price Discount Width

Locale#

Numbers are shown and read in the language of the nearest lang: typing 12.500,5 in German gives 12500.5.

Budget (de-DE) Budget (pl-PL)

Empty value#

Without value the field is empty (null) and shows the placeholder. The first button press starts from min, or 0.

Age Leave empty if you prefer not to say.

Disabled, read only and invalid#

disabled dims the field, readonly hides the buttons and keeps the value selectable, invalid on wds-field marks the error.

Disabled Read only Guests At most 8 guests.

Controlled#

wds-input fires on every change (typing, buttons, keys) with value; wds-change fires after a button or key, or when the field loses focus after typing.

Licenses
× $12 / month
Total$36 / month

Forms#

Integration with Angular forms. Pick the API your app uses.

Signal forms#

WdsNumberFieldField connects the field to [formField]; the model is number | null. With [formField] Angular does not allow min and max attributes: set them in the schema (min(), max()), which also limits the buttons.

AdultsChildrenBook

Submitted: —

Template-driven#

WdsNumberFieldValueAccessor makes ngModel work on wds-number-field. Inside a <form> each field needs a name.

AdultsChildrenBook

Submitted: —

Reactive forms#

The same WdsNumberFieldValueAccessor works with formControl and formControlName. An empty field gives null.

AdultsChildrenBook

Submitted: —

API References#

wds-number-field#

A field for a number with buttons that decrease and increase it by step. The value can also be typed, and changed with the arrow keys (Page Up/Down by ten steps, Home/End to min/max). format-options shows the number as a currency, a percentage or a unit, in the language of the nearest lang. Out-of-range values are clamped to min and max when the field loses focus. The field takes part in forms (the value is submitted as a plain number under name) and works with wds-field.

Attributes

AttributeTypeDefaultDescription
valuenumber | nullnullThe value; null when the field is empty. The attribute takes a number: value="5".
minnumber | undefinedSmallest value.
maxnumber | undefinedLargest value.
stepnumber1Step of the buttons and arrow keys; Page Up/Down move by ten steps. Values snap to it, counted from min.
format-options.formatOptionsIntl.NumberFormatOptions | nullnullHow the number is shown, as Intl.NumberFormat options, e.g. { style: 'currency', currency: 'EUR' }. The attribute takes JSON: format-options='{"style":"percent"}'. With percent the value is a fraction (0.25 = 25%).
namestring''Field name in the form.
placeholderstring''Text shown while the field is empty.
disabledbooleanfalseDisables the field and excludes it from form submission.
readonlybooleanfalseThe value can be read and selected, but not changed; the buttons are hidden.
requiredbooleanfalseA value is required for the form to be valid.
invalidbooleanfalseError state: red border and aria-invalid.
labelstring''Accessible name when the field is not in a wds-field with a label.
decrement-label.decrementLabelstring'Decrease'Accessible name of the decrease button.
increment-label.incrementLabelstring'Increase'Accessible name of the increase button.

Events

EventDescription
wds-inputCustomEvent<WdsNumberFieldChangeDetail>Every change of the value: typing, a button or a key.
wds-changeCustomEvent<WdsNumberFieldChangeDetail>A committed change: a button or a key, or the field loses focus after typing.

Methods

MethodDescription
formResetCallback()
formDisabledCallback(disabled: boolean)
formStateRestoreCallback(state: string | File | FormData | null)
stepUp(count: unknown)Increases the value by step (or by count steps).
stepDown(count: unknown)Decreases the value by step (or by count steps).
select()Selects the text of the field.
checkValidity()Returns true when the value is valid; otherwise fires invalid on the element.
reportValidity()Like checkValidity(), and shows the browser validation bubble when the value is invalid.
setCustomValidity(message: string)Sets a custom validation error (an empty string clears it), like input.setCustomValidity().

CSS parts (::part)

PartDescription
groupThe border with the buttons and the text field.
controlThe native <input>.
decrementThe decrease button.
incrementThe increase button.

Accessibility#

Screen reader#

The text field is a spinbutton with aria-valuenow, aria-valuemin, aria-valuemax, and aria-valuetext with the formatted value (e.g. "€49.90").

The field is named by the wds-field-label of a wds-field, or by label. The buttons are named "Decrease" and "Increase" (decrement-label, increment-label) and are left out of the tab order: the arrow keys do the same.

invalid sets aria-invalid. The field takes part in form validation: required, min, max and step give the browser messages, text that is not a number gives badInput.

Keyboard support#

KeyFunction
↑Increases the value by step.
↓Decreases the value by step.
Page UpPage DownChanges the value by ten steps.
HomeEndSets the value to min or max (when set).
EnterCommits the typed value and submits the form, like a native field.
Footer