# Number input (UI SDK): Controlled

> `onValueChange` runs on every valid change, and `onValueCommit` once an interaction ends, which is the one to save on. A controller steps or sets the value from any button.

Canonical: https://hextaui.com/docs/ui-sdk-number-input/examples/controlled

Component docs: https://hextaui.com/docs/ui-sdk-number-input

## Add this example

```bash
npx shadcn@latest add https://hextaui.com/r/ui-sdk-number-input-controlled.json
```

This adds `components/examples/ui-sdk-number-input/controlled.tsx` with the Number input component and the HextaUI theme tokens.

## Source

```tsx title="components/examples/ui-sdk-number-input/controlled.tsx"
"use client"

import * as React from "react"

import { Button } from "@/components/ui/button"
import { Label } from "@/components/ui/label"
import {
  NumberInput,
  NumberInputControl,
  NumberInputDecrement,
  NumberInputGroup,
  NumberInputIncrement,
  createNumberInputController,
} from "@/components/ui/ui-sdk-number-input"

function UiSdkNumberInputControlled() {
  const [seats, setSeats] = React.useState<number | null>(5)
  const [saved, setSaved] = React.useState<number | null>(5)
  const [controller] = React.useState(createNumberInputController)

  return (
    <div className="flex w-full max-w-56 flex-col gap-2">
      <Label htmlFor="seats">Seats</Label>
      <NumberInput
        controller={controller}
        value={seats}
        min={1}
        max={50}
        onValueChange={(value) => setSeats(value)}
        onValueCommit={(value) => setSaved(value)}
      >
        <NumberInputGroup>
          <NumberInputDecrement />
          <NumberInputControl id="seats" />
          <NumberInputIncrement />
        </NumberInputGroup>
      </NumberInput>
      <div className="flex items-center gap-2 pt-1">
        <Button
          size="sm"
          variant="outline"
          onClick={() => controller.increment({ large: true })}
        >
          Add 10
        </Button>
        <Button
          size="sm"
          variant="ghost"
          onClick={() => controller.setValue(1)}
        >
          Reset to 1
        </Button>
      </div>
      <p className="m-0 text-xs text-muted-foreground tabular-nums">
        {`Showing ${seats ?? "nothing"}, saved ${saved ?? "nothing"}.`}
      </p>
    </div>
  )
}

export { UiSdkNumberInputControlled }
```

## Props in this example

### NumberInput

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `number \| null` | – |  |
| `onValueChange` | `(value: number \| null, details) => void` | – |  |
| `onValueCommit` | `(value: number \| null, details) => void` | – | Runs once an interaction ends. For saving. |
| `min` | `number` | – |  |
| `max` | `number` | – |  |
| `controller` | `NumberInputController` | – | From createNumberInputController(). |

### NumberInputControl

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `id` | `string` | – |  |

## More Number input examples

- [Min and max](https://hextaui.com/docs/ui-sdk-number-input/examples/min-max)
- [Step](https://hextaui.com/docs/ui-sdk-number-input/examples/step)
- [Currency, percent and units](https://hextaui.com/docs/ui-sdk-number-input/examples/format)
- [Locale](https://hextaui.com/docs/ui-sdk-number-input/examples/locale)
- [Scrub](https://hextaui.com/docs/ui-sdk-number-input/examples/scrub)
- [Mouse wheel](https://hextaui.com/docs/ui-sdk-number-input/examples/wheel)
- [Form](https://hextaui.com/docs/ui-sdk-number-input/examples/form)
- [Invalid](https://hextaui.com/docs/ui-sdk-number-input/examples/invalid)
- [Disabled](https://hextaui.com/docs/ui-sdk-number-input/examples/disabled)
- [Read-only](https://hextaui.com/docs/ui-sdk-number-input/examples/read-only)
- [Right to left](https://hextaui.com/docs/ui-sdk-number-input/examples/rtl)
