ComponentSignal FormsUpdated in v15

Number Input

A number field with stepper buttons and locale formatting.

Installation

Import the class, and @use the entry point in your global styles: without it the component renders unstyled.

import { Component } from '@angular/core';
import { WrInputNumber } from 'ngwr/input-number';

@Component({ imports: [WrInputNumber] })
export class MyComponent {}

Basic

The value is number | null, formatted in Angular's LOCALE_ID.

<wr-input-number [(value)]="value" />

Min / max / step

Edits stay inside [min] / [max]; arrows move one step, Shift + arrow ten.

<wr-input-number [(value)]="value" [min]="0" [max]="100" [step]="5" />

Prefix and decimals

decimals rounds the value and shows that many places on blur.

<wr-input-number [(value)]="price" prefix="$" [decimals]="2" />
$

Suffix and fractional step

<wr-input-number [(value)]="weight" suffix="kg" [decimals]="1" [step]="0.1" />
kg

Without steppers

[showSteppers]="false" hides the buttons.

<wr-input-number [(value)]="value" [showSteppers]="false" />

Gotchas

  • An emptied field is null, not 0.
  • A value set from outside [min] / [max] is kept as is. Flag it with Validators.max.
  • With [formField], set the bounds with the schema's min() / max().

API

NameDescriptionTypeDefault
minMinimum allowed value.number | undefined-Infinity
maxMaximum allowed value.number | undefinedInfinity
stepStep used by stepper buttons + arrow keys.number1
decimalsFixed number of decimals. Rounds the value as it is COMMITTED, and fixes the digits shown once the field reformats on blur. null keeps the entered precision and formats with up to 20. Clamped to 0–100, the range Intl.NumberFormat's minimumFractionDigits / maximumFractionDigits accept — because it is the one numeric input on this component that had no transform, and the value goes straight into the formatter, which THROWS a RangeError outside that range rather than degrading. A [decimals]="-1" bound from a config object took the whole component down on blur.number | nullnull
showSteppersRender the ▲▼ stepper column.booleantrue
sizeControl size — forwarded to the field's [size], and shares the --wr-control-* contract.WrInputSize'md'
roundedPill-shaped corners — forwarded to the group AND the field.booleanfalse
prefixOptional prefix label (e.g. "$").string''
suffixOptional suffix label (e.g. "kg").string''
placeholderPlaceholder shown when the input is empty.string''
ariaLabelAccessible name for the field. Unset, the field is named by whatever labels it — there is deliberately no fallback here. It used to mirror the placeholder, and an aria-label OUTRANKS a <label> in the accname order: inside a <wr-form-field label="Quantity"> the very input that adopts the field's id announced the placeholder ("0") instead, and a placeholder disappears as soon as the user types. Standalone nothing was lost by dropping it — an input with no other name already falls back to its own placeholder attribute, which is the name axe's label rule accepts too.string | nullnull
incrementLabelIncrement button aria-label. Falls back to inputNumber.increment.string | nullnull
decrementLabelDecrement button aria-label. Falls back to inputNumber.decrement.string | nullnull
disabledDisable interaction.booleanfalse
readonlyRead-only — values cannot be changed (steppers + typing disabled).booleanfalse
valueNumeric value (null when empty). Bound by [formField], or two-way via [(value)].number | nullnull
(touch)Emitted on blur so a bound field can mark itself touched.void—

CSS variables

Set these on the component's selector or a wrapper, not on :root: the defaults are declared on ngwr/input-number's own element.

VariableDefaultDeclared on
--wr-input-number-step-cap-radiusvar(--wr-border-radius-pill).wr-input-number
--wr-input-number-step-icon-sizevar(--wr-control-font-size-md).wr-input-number +2 variant overrides

Dependencies

Built onInput
Used bySchema Form

See also