NumberField
Composable numeric input with formatted text entry, spinbutton semantics, stepper buttons, optional wheel scrubbing, and pointer scrubbing.
value: 42
Anatomy
NumberField.Root provides state to every part. Group wraps the visible controls, Input is the spinbutton text input, and Decrement / Increment are the stepper buttons. ScrubArea (with an optional ScrubAreaCursor) adds pointer scrubbing.
<script>
import { NumberField } from '@human-kit/ui';
</script>
<NumberField.Root>
<NumberField.ScrubArea>
<NumberField.ScrubAreaCursor />
</NumberField.ScrubArea>
<NumberField.Group>
<NumberField.Decrement />
<NumberField.Input />
<NumberField.Increment />
</NumberField.Group>
</NumberField.Root>Formatting
The visible text is formatted with Intl.NumberFormat via formatOptions, while bind:value always stays a raw number | null. Wrap the component in LocaleProvider to control locale-aware parsing and formatting.
raw value: 1234.5
Scrubbing
NumberField.ScrubArea turns any element into a pointer-drag control for the value, and allowWheelScrub lets the mouse wheel step the value while the input is focused. Both expose data-scrubbing for styling.
value: 12
Usage guidelines
- Provide an accessible name for
NumberField.Inputwitharia-label,aria-labelledby, or a visible<label for>. - Use
bind:valuefor two-way state. The value is alwaysnumber | null; the visible input text is formatted separately. - Wrap the component in
LocaleProviderto control locale-aware parsing and formatting. - With
allowOutOfRange={false}, out-of-range drafts remain editable while focused and clamp tominormaxon commit. - Percent formatting treats
%as a localized display suffix: typing50publishes50, not0.5. - Use
nameonRootonly when the component should submit a raw numeric value in an HTML form. incrementAriaLabelanddecrementAriaLabeloverride the localized defaults when custom control names are needed.
Accessibility
NumberField.Inputrenders a text input withrole="spinbutton"and exposesaria-valuemin,aria-valuemax,aria-valuenow, andaria-valuetextwhen applicable.- Arrow keys step by
step,Shift+ arrows step bylargeStep,Ctrl/Cmd+ arrows step bysmallStep, andPageUp/PageDownandHome/Endare supported. - Pointer scrub has equivalent input, keyboard, and button controls.
- Invalid drafts and out-of-range values set native custom validity on the visible input so form submission is blocked while the field is invalid.
API reference
Root
The number field container. Owns the numeric state, formatting, and validation, provides context to all parts, and renders a hidden input that submits the raw number when `name` is set.
* required. Native HTML attributes of the underlying element are also accepted.
Group
Groups the visible controls (input and stepper buttons) and mirrors the field state through data attributes.
* required. Native HTML attributes of the underlying element are also accepted.
Input
The visible text input with role="spinbutton". Handles formatted text entry, keyboard stepping, and native validity.
* required. Native HTML attributes of the underlying element are also accepted.
Increment
Stepper button that increases the value by `step`. Excluded from the tab order and labeled with a localized default.
* required. Native HTML attributes of the underlying element are also accepted.
Decrement
Stepper button that decreases the value by `step`. Excluded from the tab order and labeled with a localized default.
* required. Native HTML attributes of the underlying element are also accepted.
ScrubArea
Turns its content into a pointer-drag control that steps the value while dragging.
* required. Native HTML attributes of the underlying element are also accepted.
ScrubAreaCursor
Optional virtual cursor rendered while scrubbing, following the pointer inside the scrub area.
* required. Native HTML attributes of the underlying element are also accepted.