Currency Input
NewMoney field that formats as you type for any currency and locale, keeps the caret in place and returns a plain number.
Values: 1250.5 and 980
Installation
$ pnpm dlx shadcn@latest add @synccn/currency-inputFirst time in this project? Connect synccn with one command.
Usage
import { CurrencyInput } from "@/components/ui/currency-input";<CurrencyInput value={price} onValueChange={setPrice} currency="EUR" locale="de-DE" />API reference
Generated from the component's TypeScript types, so it always matches the code.
CurrencyInput
Money field that formats as you type (1,234.50), keeps the caret in place, accepts pasted amounts like "$1,200" or "1.200,50", and gives you a plain number back.
- value
number | nullControlled amount, as a number. null when empty.
- defaultValue
number | nullDefault
nullAmount at first, when uncontrolled.
- onValueChange
(value: number | null) => voidCalled with the amount as a number (or null when cleared).
- currency
stringDefault
"USD"ISO currency code.
- locale
stringDefault
"en-US"Locale for separators and the symbol's position.
- min
numberSmallest amount allowed. Values below are clamped when the field loses focus.
- max
numberLargest amount allowed.
- invalid
booleanMarks the field invalid.
- className
stringExtra classes for the root element.
Also accepts every standard <input> attribute, and forwards its ref.
Dependencies
Read from the component's imports when the site builds. The CLI installs all of these for you.
Helpers
- lib/utilscn (merges class names)
npm packages
- clsx for cn()
- tailwind-merge for cn()
Accessibility
- Uses inputMode="decimal" for the right phone keyboard. The currency code is visible text, not just a symbol.
From the source
Read from this component's code when the site builds, so it can't drift.
- ARIA attributes: aria-invalid