Skip to content

Inputs

NumberField

Bit.BlazorUINumberInput

A NumberField (number input, spin button) edits a value of any .NET numeric type, with bounds, stepping and snapping, rounding, .NET formatting in any culture, spin buttons in three layouts, the full ARIA spinbutton keyboard set and EditForm validation.

Events, API & validation

The spin, bound and key events, driving the field from code, validation inside an EditForm, and the ARIA spinbutton semantics.

Events

OnIncrement/OnDecrement fire for every spin, whatever the device; OnMinReached/OnMaxReached once per approach to an explicit bound. OnEnter runs after the typed text commits, OnEscape before the field clears. Key, click and focus events are surfaced too.

OnIncrement Counter: 0
OnDecrement Counter: 0

OnChange Counter: 0

[]

[]

Escape pressed 0 time(s)

Last key down: []
OnKeyUp Counter: 0
OnClick Counter: 0

Public API

IncrementAsync, DecrementAsync and ClearAsync do what the field's own controls do - bounds, snapping and callbacks included - and are safe from any thread. FocusAsync focuses the input (the increment button with HideInput).

value: [4]

Validation

Works with EditForm and data annotations. Unparsable text stays in the input with ParsingErrorMessage ({0} is the DisplayName). Pair NoClamp with [Range] to report rather than correct.

ShowValidationMessage shows the messages of the form - a ParsingErrorMessage among them - under the field, where ErrorMessage goes, so the forms below need no ValidationMessage component. The input is described by them through aria-describedby, so they are read out when it takes the focus, and an ErrorMessage of the app's own wins the place while it is set. They are not announced as they appear: a submit validates every field at once, and a message from each of them read out in a row would bury the form under its own errors. A BitParams holding a BitNumberFieldParams with ShowValidationMessage turns it on for every field inside it.




Accessibility

The input is an ARIA spinbutton: aria-valuenow/min/max stay in sync, aria-valuetext is added when the text differs from the number (AriaValueText overrides it), and aria-required/aria-readonly are written out. The buttons are named (IncrementAriaLabel, DecrementAriaLabel, ClearButtonAriaLabel), point aria-controls at the input, and step on an assistive technology's activation too; a step the input did not take focus for is announced through a live region. On touch, Compact buttons grow to the 24px minimum target. AriaSetSize/AriaPositionInSet place the field in a set.

Use the up and down arrow keys to adjust the volume between 0 and 10.


Feedback

Found a mistake, a gap, or something that could be clearer? Every page and every component is one click from its source.