NumberInput
Numeric input with draft-safe typed value callbacks and optional affixes.
Preview
A live, theme-aware example rendered with the published component.
Loading preview…
Import
Import from the focused entry point below, or use the same named export from @tavojs/ui. Both are public APIs; measure the built application when comparing their bundle cost.
tsximport { NumberInput } from "@tavojs/ui/number-input";The component import loads compiled component CSS. Enable tavoUi() for your project theme variables, or import @tavojs/ui/theme.css once for the package default theme. The equivalent CSS-safe component alias is @tavojs/ui/css/number-input.
When to use
Use it when
Choose something else when
Examples
These examples include imports and local state where interaction requires it. Render the exported component in a page after completing UI installation. Demo state stays in the mounted component; connect file handling, persistence, and data loading to your application as needed.
NumberInput example
tsximport { createTavo } from "@tavojs/core";
import { NumberInput } from "@tavojs/ui/number-input";
import { Text } from "@tavojs/ui";
type State = { width: number | null; savedWidth: number | null };
export const NumberInputExample1 = createTavo<Record<string, never>, State>({
model: () => ({ width: 320, savedWidth: 320 }),
view: ({ state, model }) => (
<>
<NumberInput
label="Width"
value={state.width}
min={0}
step={1}
suffix="px"
onValueInput={(width) => model.set("width", width)}
onValueChange={(width) => model.patch({ width, savedWidth: width })}
/>
<Text>Committed width: {state.savedWidth ?? "unset"}</Text>
</>
)
});Common props and defaults
A curated starting point. The complete TypeScript API below includes additional props and compound member contracts.
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | — | Optional class hook applied to the public root element owned by the component. |
value | number | null | — | Controlled numeric or unset value. |
defaultValue | number | null | — | Initial uncontrolled value. |
step | number | — | Arrow-key increment. |
label | Child | — | Visible accessible label. |
onValueInput | (value, draft) => void | — | Typed transient callback for valid drafts. |
onValueChange | (value, draft) => void | — | Typed commit callback. |
Complete TypeScript API
Import from @tavojs/ui/number-input. Published exports: NumberInput, NumberInputDraft, NumberInputProps, NumberInputValue, parseNumberInputDraft.
NumberInputProps
| Property | Type | Required | Description |
|---|---|---|---|
className | string | No | Optional class hook applied to the public root element owned by the component. |
size | Size | No | Inherited size attribute accepted by NumberInput. |
label | Child | No | Visible accessible label. |
prefix | Child | No | Inherited prefix attribute accepted by NumberInput. |
suffix | Child | No | Inherited suffix attribute accepted by NumberInput. |
value | number | No | Controlled numeric or unset value. |
defaultValue | number | No | Initial uncontrolled value. |
min | number | No | Inherited min attribute accepted by NumberInput. |
max | number | No | Inherited max attribute accepted by NumberInput. |
step | number | No | Arrow-key increment. |
name | string | No | Inherited name attribute accepted by NumberInput. |
placeholder | string | No | Inherited placeholder attribute accepted by NumberInput. |
required | boolean | No | Inherited required attribute accepted by NumberInput. |
readOnly | boolean | No | Inherited readOnly attribute accepted by NumberInput. |
disabled | boolean | No | Inherited disabled attribute accepted by NumberInput. |
allowUnset | boolean | No | Inherited allowUnset attribute accepted by NumberInput. |
onValueInput | (value: NumberInputValue, draft: string) => void | No | Typed transient callback for valid drafts. |
onValueChange | (value: NumberInputValue, draft: string) => void | No | Typed commit callback. |
onInput | ValueChangeHandler<HTMLInputElement> | No | Inherited onInput attribute accepted by NumberInput. |
onChange | ValueChangeHandler<HTMLInputElement> | No | Inherited onChange attribute accepted by NumberInput. |
onKeyDown | TavoEventHandler<KeyboardEvent> | No | Inherited onKeyDown attribute accepted by NumberInput. |
State ownership and DOM target
| Concern | Contract |
|---|---|
| State | Use value to supply rendered state. Update it through the documented callback or native event handler. For browser-owned initial values, use defaultValue instead. |
| DOM target | sx and className style the wrapper. Native input attributes and input events target the owned input control. |
Anatomy and related components
This component exposes one public component root rather than a compound member API.
Limitations
Avoid NumberInput when wrapping controls without labels or accessible names.
Use only the documented props, entry points, and compound members. Internal DOM nesting and CSS class names can change without becoming part of the public component contract.
Accessibility
The visible label wraps the input, affixes are hidden from assistive technology, and Arrow keys support native-like stepping with Shift for a larger increment.
The visible label wraps the input, affixes are hidden from assistive technology, and Arrow keys support native-like stepping with Shift for a larger increment.
Component status
| Contract | Current value |
|---|---|
| Maturity | stable |
| Category | forms |
| Component import | @tavojs/ui/number-input |
| Explicit CSS import | @tavojs/ui/css/number-input |
| Preview | Interactive preview available on this page |