UIComponentsReact
A text field for an amount of money that formats it in the locale's way while it is typed, with the currency drawn inside the text or next to it.
Built on the headless Currency Input.See its API in Docs
Rendered by React 19.3.1
Installation
npx shadcn@4.23.0 add https://hamur.dev/r/react/currency-input.jsonIt also adds utils. The app needs its setup first: Installation.
Usage
Put a CurrencyInputInput inside CurrencyInput and give CurrencyInput the currency (an ISO 4217 code such as USD), the amount as a decimal string in value or defaultValue, and a locale when it should not be the runtime's. With currencyPlacement="outside", add a CurrencyInputSymbol: it draws the currency in the muted colour on the side the locale puts it, wherever it sits in the markup. Its content replaces the currency text (React: render with the state's symbol and side; Vue: the default slot { symbol, side }; Svelte: the children snippet with the state; Solid: a function child; Angular: symbol() and side() of #symbol="uiCurrencyInputSymbol"). Name the field with a Field label or aria-label. The typing, the caret, the paste handling, the undo history, the range, the events and the form value come from the headless Currency Input.
import { CurrencyInput, CurrencyInputInput, CurrencyInputSymbol } from '@/components/ui/currency-input'Examples
Default
An amount in US dollars in a Field: the Symbol $ outside the text, 1,234.50 at the end, a description.
The Root is the Number Field's group box, so the field reads as one box with or without a Symbol, and it shows the focus ring while the Input has focus (WCAG 2.4.7). The Input aligns the amount to its end in tabular figures. The Symbol's muted colour is at least 4.5:1 against the Root's background in every preset theme, light and dark (WCAG 1.4.3); it is hidden from assistive technology, which reads the currency from the Input's value and label. A disabled field draws the Root at half opacity. This item takes Base UI's component ID as its slug and one name per Base UI part.
API reference
The styled parts pass every prop to the headless part they wrap and add classes. The props, data attributes and keyboard are on Currency Input's API reference.