Skip to content
synccn

Currency Input

New

Money field that formats as you type for any currency and locale, keeps the caret in place and returns a plain number.

USD
EUR

Values: 1250.5 and 980

Installation

$ pnpm dlx shadcn@latest add @synccn/currency-input

First 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 | null

    Controlled amount, as a number. null when empty.

  • defaultValue
    number | null

    Default null

    Amount at first, when uncontrolled.

  • onValueChange
    (value: number | null) => void

    Called with the amount as a number (or null when cleared).

  • currency
    string

    Default "USD"

    ISO currency code.

  • locale
    string

    Default "en-US"

    Locale for separators and the symbol's position.

  • min
    number

    Smallest amount allowed. Values below are clamped when the field loses focus.

  • max
    number

    Largest amount allowed.

  • invalid
    boolean

    Marks the field invalid.

  • className
    string

    Extra 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

npm packages

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