HextaUI

Number input (UI SDK): Currency, percent and units

format takes Intl.NumberFormat options. People can type in the same format, and a percent is a fraction, so 15% is 0.15. The variant="stacked" group puts small chevrons at the end.

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

const fields = [
  {
    id: "price",
    label: "Price",
    defaultValue: 19.99,
    step: 0.01,
    format: { style: "currency", currency: "USD" },
  },
  {
    id: "discount",
    label: "Discount",
    defaultValue: 0.15,
    step: 0.01,
    format: { style: "percent" },
  },
  {
    id: "weight",
    label: "Weight",
    defaultValue: 2.5,
    step: 0.1,
    format: { style: "unit", unit: "kilogram" },
  },
] satisfies {
  id: string
  label: string
  defaultValue: number
  step: number
  format: Intl.NumberFormatOptions
}[]

function UiSdkNumberInputFormat() {
  return (
    <div className="flex w-full max-w-44 flex-col gap-4">
      {fields.map(({ id, label, ...options }) => (
        <div key={id} className="flex flex-col gap-2">
          <Label htmlFor={id}>{label}</Label>
          <NumberInput {...options} min={0} locale="en-US">
            <NumberInputGroup variant="stacked">
              <NumberInputControl id={id} />
              <NumberInputStepper>
                <NumberInputIncrement />
                <NumberInputDecrement />
              </NumberInputStepper>
            </NumberInputGroup>
          </NumberInput>
        </div>
      ))}
    </div>
  )
}

export { UiSdkNumberInputFormat }

This adds the example as components/examples/ui-sdk-number-input/format.tsx, together with the Number input component and the HextaUI theme tokens it needs.

pnpm dlx shadcn@latest add https://hextaui.com/r/ui-sdk-number-input-format.json

To add only the component, follow the Number input installation.

Props in this example

The Number input props this example sets, from the API reference.

PropTypeDefault
min
number–
localeDefaults to the page’s language.
string–
PropTypeDefault
variantButtons on both sides, chevrons stacked at the end, or no buttons, for a scrub handle.
"split" | "stacked" | "plain""split"
PropTypeDefault
id
string–

Every prop is in the Number input API reference.

See them all, with keyboard support and accessibility notes, on the Number input page.