# NumberInput

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

Status: beta. Category: Forms.

```ts
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

| Prop | Type | Default | Description |
|---|---|---|---|
| `defaultValue` | `number \| null` |  |  |
| `formatOptions` | `NumberFormatOptions` |  | Display formatting when the field isn't focused, e.g. `{ style: 'currency', currency: 'USD' }`. |
| `hideSteppers` | `boolean` |  | Hide the − / + buttons. |
| `inputClassName` | `string` |  | Classes for the `<input>` element. `className` styles the outer frame. |
| `locale` | `string` |  | Locale for formatting. Defaults to the browser's. |
| `max` | `number` |  |  |
| `min` | `number` |  |  |
| `onValueChange` | `((value: number \| null) => void)` |  |  |
| `prefix` | `ReactNode` |  |  |
| `size` | `"sm" \| "md" \| "lg"` |  |  |
| `step` | `number` |  | Amount added or removed by the steppers and arrow keys. Shift multiplies by 10. Default 1. |
| `suffix` | `ReactNode` |  | Content after the number, before the steppers, e.g. a unit. |
| `value` | `number \| null` |  | `null` means empty. |

## Example: Quantity

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

```tsx
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.

```tsx
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
