Skip to content

NumberInput

A native number input with the Viam border and padding. It renders one <input type="number">, so class lands on it and the consumer owns its width. Inside a Field it takes its id (the field’s controlId), disabled, required, state, and aria-describedby from there. Inside an Input.Group it goes borderless.

<NumberInput id="qty" min={0} max={10} bind:value />
<NumberInput
  value={3}
  min={0}
  max={10}
  step={1}
  state="none"
/>
  • Its own native <input type="number">. It takes the same state as Input and works inside an Input.Group with a Field.StateIcon.
  • value is number | undefined. No string parsing on your side.
  • min, max, and step are the native attributes. The browser owns stepping, spin buttons, and the wheel.

Clear the field and the value becomes undefined.

value: 3

Code
TwoWay.svelte
<script lang="ts">
import { Field, Hint, Label, NumberInput } from "@viamrobotics/prime-ui";
let count = $state<number | undefined>(3);
</script>
<div class="not-content">
<Field class="flex max-w-3xs flex-col gap-1">
<Label>Quantity</Label>
<NumberInput bind:value={count} min={0} max={10} step={1} />
<Hint>Clear the field and the value becomes undefined.</Hint>
</Field>
<p class="mt-3 text-sm text-subtle-2">value: <code>{count ?? "undefined"}</code></p>
</div>

For the controlled mode, see State & binding.

Error state, with Field.StateIcon

Disabled and read-only

Same as Input: class lands on the <input>, and it carries no width. Inside an Input.Group the input goes borderless and the group carries the border. The input carries data-field-state and aria-invalid from state.

Native number input behavior: ArrowUp and ArrowDown step by step within min and max. Nothing is added or intercepted.

PropTypeDefaultDescription
bind:valuenumberCurrent value. An empty field is undefined.
minnumberThe minimum allowed value.
maxnumberThe maximum allowed value.
stepnumber | 'any'1Step for keyboard or spin-button increments, and the granularity constraint validation enforces. 'any' accepts every decimal, which no number can express.
stateFieldStateContextual state. Defaults to the enclosing field's state.

Plus everything in Omit< HTMLInputAttributes, 'value' | 'min' | 'max' | 'step' | 'type' | 'children' >, spread onto the element.