Navigated to /docs/ui/components/number-input

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.

TSX
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

Use `NumberInput` for numeric values that need typed preview and commit callbacks while preserving empty, signed, and decimal typing drafts

Choose something else when

Avoid NumberInput when wrapping controls without labels or accessible names.

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

TSXCreate: src/components/examples/NumberInputExample1.tsx
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.

PropTypeDefaultDescription
classNamestring

Optional class hook applied to the public root element owned by the component.
valuenumber | null

Controlled numeric or unset value.
defaultValuenumber | null

Initial uncontrolled value.
stepnumber

Arrow-key increment.
labelChild

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

PropertyTypeRequiredDescription
classNamestring

No

Optional class hook applied to the public root element owned by the component.

sizeSize

No

Inherited size attribute accepted by NumberInput.

labelChild

No

Visible accessible label.

prefixChild

No

Inherited prefix attribute accepted by NumberInput.

suffixChild

No

Inherited suffix attribute accepted by NumberInput.

valuenumber

No

Controlled numeric or unset value.

defaultValuenumber

No

Initial uncontrolled value.

minnumber

No

Inherited min attribute accepted by NumberInput.

maxnumber

No

Inherited max attribute accepted by NumberInput.

stepnumber

No

Arrow-key increment.

namestring

No

Inherited name attribute accepted by NumberInput.

placeholderstring

No

Inherited placeholder attribute accepted by NumberInput.

requiredboolean

No

Inherited required attribute accepted by NumberInput.

readOnlyboolean

No

Inherited readOnly attribute accepted by NumberInput.

disabledboolean

No

Inherited disabled attribute accepted by NumberInput.

allowUnsetboolean

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.

onInputValueChangeHandler<HTMLInputElement>

No

Inherited onInput attribute accepted by NumberInput.

onChangeValueChangeHandler<HTMLInputElement>

No

Inherited onChange attribute accepted by NumberInput.

onKeyDownTavoEventHandler<KeyboardEvent>

No

Inherited onKeyDown attribute accepted by NumberInput.

State ownership and DOM target

ConcernContract
StateUse value to supply rendered state. Update it through the documented callback or native event handler. For browser-owned initial values, use defaultValue instead.
DOM targetsx 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

ContractCurrent value
Maturitystable
Categoryforms
Component import@tavojs/ui/number-input
Explicit CSS import@tavojs/ui/css/number-input
PreviewInteractive preview available on this page