Skip to content
Stylhero 0.6.2
React Native

Theme

Core

Feedback

Inputs

Navigation

Overlays

React Native / Inputs

NumberInput

Number field with − and + buttons. Typing is free; the value is kept within min/max when the field loses focus. The buttons say what they change ("Increase Quantity") and the new value is announced after each step.

import { NumberInput } from "@stylhero/native";

Example

import { useState } from "react";
import { NumberInput } from "@stylhero/native";

function NumberInputExample() {
  const [budget, setBudget] = useState<number | null>(1500);
  return (
    <NumberInput
      label="Budget"
      value={budget}
      onChange={setBudget}
      min={500}
      max={10000}
      step={100}
      prefix="$"
      hint="From $500 to $10,000"
    />
  );
}

Props

PropTypeDefaultDescription
label required string -
onChange required (value: number | null) => void - Called with each valid number typed (not yet clamped), null when cleared, and the clamped value on blur or a step.
value required number | null - The number, or null while the field is empty.
announceError boolean - Announce a new error (see TextField). Set it to false when the form focuses the field instead. Default true.
decreaseLabel string `Decrease ${label}` Spoken names of the step buttons. Default "Decrease {label}" / "Increase {label}".
disabled boolean -
error string -
hint string -
increaseLabel string `Increase ${label}`
max number -
min number -
placeholder string -
precision number decimalsOf(step) Decimals kept when the value is rounded (on blur and each step). Default: the step's decimals (step 0.5 → 1). Set it higher to allow finer typed values than the buttons move by, e.g. step={1} precision={1} keeps 2.5%. Trailing zeros past the step's decimals aren't shown ("5", not "5.0").
prefix string - Short unit text inside the field, e.g. "$" before or "%" after.
ref Ref<ComponentRef<typeof TextInput>> - The text input, e.g. to focus the field when a form finds it invalid.
step number 1 How much − and + change the value. Default 1.
style StyleProp<ViewStyle> -
suffix string -
testID string -

Screen reader gestures

Gesture (VoiceOver / TalkBack)Does
Double-tap − or +Changes the value by step and reads the new value

Accessibility

  • The visible label is the accessible name; the hint, or the error when there is one, is read as the accessibility hint.
  • The buttons are named after the field ("Increase Budget") and are disabled at min and max.
  • The allowed range is part of the hint. Typed values are kept within range when the field loses focus.

Generated from src/components/NumberInput.tsx. Something wrong or missing? Open an issue.