NumberInput

A number field with − / + steppers, arrow-key stepping, min/max clamping and locale formatting.

Status: beta. Category: Forms.

import { NumberInput } from '@glyphui/ui'

Exports: NumberInput, numberInputStyles.

Notes

  • The value is number | null (empty), never a string.
  • Typed values outside min/max are clamped when the field loses focus.
  • Home and End jump to min and max.

NumberInput props

PropTypeDefaultDescription
defaultValuenumber | null
formatOptionsNumberFormatOptionsDisplay formatting when the field isn't focused, e.g. { style: 'currency', currency: 'USD' }.
hideSteppersbooleanHide the − / + buttons.
inputClassNamestringClasses for the <input> element. className styles the outer frame.
localestringLocale for formatting. Defaults to the browser's.
maxnumber
minnumber
onValueChange((value: number | null) => void)
prefixReactNode
size"sm" | "md" | "lg"
stepnumberAmount added or removed by the steppers and arrow keys. Shift multiplies by 10. Default 1.
suffixReactNodeContent after the number, before the steppers, e.g. a unit.
valuenumber | nullnull means empty.

Example: Quantity

Min, max and step. Shift + arrow steps by 10.

import { Field, NumberInput } from '@glyphui/ui'
import { useState } from 'react'

export default function Example() {
  const [seats, setSeats] = useState<number | null>(5)
  return (
    <Field
      label="Seats"
      description={`${seats ?? 0} × $16 = ${(seats ?? 0) * 16} per month`}
      className="w-56"
    >
      <NumberInput value={seats} onValueChange={setSeats} min={1} max={250} />
    </Field>
  )
}

Example: Currency

Formatted while idle, raw while editing; the value stays a number.

import { Field, NumberInput } from '@glyphui/ui'

export default function Example() {
  return (
    <div className="grid w-full max-w-md gap-4 sm:grid-cols-2">
      <Field label="Monthly budget">
        <NumberInput
          defaultValue={2500}
          min={0}
          step={50}
          locale="en-US"
          formatOptions={{ style: 'currency', currency: 'USD', maximumFractionDigits: 0 }}
        />
      </Field>
      <Field label="Discount">
        <NumberInput defaultValue={15} min={0} max={100} step={5} suffix="%" />
      </Field>
    </div>
  )
}

Live page: https://glyphui.xyz/components/number-input