Money
A currency amount input with live digit grouping, ghost cents, fit-to-width scaling, rolling digits, quick add chips, and minor-unit output.
import { MoneyInput } from '@uthereal/ui/money-input'Money input playground
Overview
MoneyInput renders a labelled currency field built for monetary entry. Digits group live as you type without moving the caret, and missing fraction digits render as faint ghosts that hold their width so settling on blur or Enter never shifts the layout. Long amounts scale down to fit the shell instead of scrolling, up to 12 integer digits.
Values enter and leave as minor-unit integers ($12.50 is 1250, ¥500 is 500, and null is empty), avoiding floating-point rounding drift. Quick add chips and arrow keys roll the digits on odometer wheels, while typing cuts straight to the result so the caret never lags. When currencies lists more than one ISO 4217 code, a currency menu sits at the end of the shell; a single code locks the currency and renders a static label.
Use MoneyInput for prices, payouts, budgets, and donations where minor-unit precision and currency metadata matter. Use Number for general quantities, counts, or percentages with +/- steppers.
Usage
'use client'
import { useState } from 'react'
import { MoneyInput, type MoneyInputDetails } from '@uthereal/ui/money-input'
export function PayoutAmount() {
const [amount, setAmount] = useState<number | null>(2500)
const [currency, setCurrency] = useState('USD')
function handleChange(next: number | null, _details: MoneyInputDetails) {
setAmount(next)
}
return (
<MoneyInput
label="Payout amount"
name="amount_minor"
value={amount}
onValueChange={handleChange}
currency={currency}
onCurrencyChange={setCurrency}
min={500}
max={50000}
/>
)
}Omit value and currency for an uncontrolled field initialized from defaultValue and defaultCurrency. When name is set, a hidden <input type="hidden"> submits the current minor-unit integer (or an empty string when null) with native HTML forms.
Examples
Currencies and locales
Currency symbols, symbol position (prefix or suffix), fraction digits, and localized names derive from cached Intl.NumberFormat and Intl.DisplayNames instances. Passing a single entry in currencies locks the field and hides the menu, and zero-decimal currencies such as JPY omit ghost cents and switch the virtual keyboard to inputMode="numeric". Set locale for deterministic separators and symbol placement; omit it to inherit the locale from UtherealProvider or fall back to en-US so server and browser output match.
Bounds and quick add
min, max, and step are specified in minor units, while quickAdd chips use major units (pass [] to hide them). Typing past max refuses the keystroke with a sideways spring kick, flashes the range summary, and announces the ceiling. Entering an amount below min keeps the typed draft while focused and displays the built-in minimum message on blur until the host or user corrects it.
API reference
These serializable arguments and defaults come directly from the component schema.
| Argument | Type / default | Description |
|---|---|---|
label | stringDefault: "Amount" | Visible label and accessible name. Name the information asked for, in sentence case. |
hideLabel | booleanDefault: false | Hide the label visually when the context already names the field. It is still announced. |
description | string— | Supporting text below the field, announced with it. Use it for format hints and constraints. |
error | string— | Validation message from your application. Setting it marks the field invalid; the message is linked to the field and announced politely. |
required | booleanDefault: false | Marks the field as required for assistive technology and shows an indicator. Your application validates the value. |
readOnly | booleanDefault: false | The value can be focused, selected, and copied, but not edited. It is still submitted with a form. |
disabled | booleanDefault: false | Unavailable and removed from the tab order. A disabled field is not submitted with a form. |
name | string— | Native form field name, submitted with the value in a form. |
defaultValue | integer | nullDefault: null | Initial amount in minor units ($12.50 is 1250), or null for empty. Later argument edits do not reset an existing instance; use value and onValueChange to control it. |
defaultCurrency | stringDefault: "USD" | Initial ISO 4217 currency code, USD by default. It must appear in currencies. |
currencies | string[]Default: ["USD","EUR","GBP","JPY","CAD","AUD","CHF","INR"] | Codes the currency menu offers, at most 32. Pass a single code to lock the currency and hide the menu. |
min | integer— | Lowest amount in minor units; a blurred value below it shows a message and stays as typed until the host corrects it. |
max | integer— | Highest amount in minor units; typing past it is refused with a sideways nudge and the range flashes. |
step | integer— | Amount the arrow keys add or remove, in minor units; omitted means one major unit ($1). Shift and an arrow or PageUp/PageDown move ten steps. |
quickAdd | number[]Default: [10,50,100] | Quick add chips in major units ($10, $50, $100 by default); at most 8. An empty array hides the chips. |
locale | string— | BCP 47 locale for separators, symbols and currency names, e.g. en-US or de-DE. Omit it to use the application locale (UtherealProvider), else en-US; never the browser’s, so server and browser render the same text. |
labels | object— | Reader-facing copy: the menu, chips and range messages. |
variant | outline | soft | ghostDefault: "outline" | Field surface: outline in forms, soft, or ghost inline. |
size | sm | md | lgDefault: "md" | Field height and text size. |
recipe | studio | softDefault: "studio" | Visual treatment. Both recipes use the same interaction behavior. |
theme | MoneyInputTheme— | Color mode, accent, and semantic tokens. See Theming for all keys and defaults. |
motion | none | subtle | expressiveDefault: "subtle" | Rolling digits, the refusal kick, the symbol roll and message copy. Reduced motion keeps short fades; none makes every change immediate. |
motionOptions | object— | Fine tune the digit roll: the column stagger and the chip press scale. |
dir | ltr | rtl— | Reading direction. Omit it to inherit the page direction. |
React integration
| Prop | Purpose |
|---|---|
value, onValueChange | Controlled minor-unit amount (number | null). Callback receives (value, details). |
currency, onCurrencyChange | Controlled ISO 4217 currency code (string) and selection callback. |
ref | Ref to the native <input> element. |
portalContainer | Custom portal target for the currency menu (defaults to enclosing layer or body). |
preset | Application defaults (such as locale, labels, quickAdd), overridden by props. |
tokens | CSS custom properties (--ui-*) applied after the typed theme on root and portal. |
className, style | Applied to the root field element, which carries the resolved tokens. |
| Native attributes | Forwarded to <input> (onBlur, onKeyDown, autoFocus, aria-*). |
MoneyInputDetails provides { currency: string, major: number | null, formatted: string } on every change.
Keyboard & accessibility
| Key | Interaction |
|---|---|
ArrowUp, ArrowDown | Add or subtract one step (defaults to one major unit) in the amount input. |
Shift + arrows, PageUp/PageDown | Add or subtract ten step units. |
Enter | Settle the typed draft and pad missing fraction digits. |
Backspace, Delete | Crossing a group separator deletes the adjacent digit instead of stalling. |
ArrowDown, ArrowUp (menu button) | Open the currency picker listbox and highlight the active currency. |
ArrowUp/Down, Home, End | Move focus through currency options inside the open listbox. |
| Character keys (menu open) | Typeahead matches currency codes (EUR) and localized names (Japanese Yen). |
Enter, Space (menu open) | Select the highlighted currency, convert the draft, and return focus to trigger. |
Escape (menu open) | Close the currency menu and restore focus to the currency button. |
The input exposes role="spinbutton" with aria-valuenow (major units), aria-valuetext (full formatted currency string or "Empty"), and aria-valuemin/aria-valuemax when bounded. Its inputMode switches between decimal (currencies with fraction digits) and numeric (zero-decimal currencies such as JPY). Pasting formatted currency strings such as "$1,234.56" or "1.234,56 €" extracts digits and the final decimal separator cleanly.
Quick add chips sit in a labelled role="group" referencing the input with aria-controls. At max, chips set aria-disabled="true" so keyboard users can still reach them and trigger limit feedback. Arrow steps, quick add chips, currency switches, and limit refusals announce through a pre-mounted role="status" (aria-live="polite") region. Layout spacing and scaling anchor follow logical CSS and dir="rtl", and forced-colors: active preserves borders, ghost contrast, highlighted menu options, and focus outlines.
Motion and theming
- Rolling digits: arrow keys, quick add chips, and external value changes spin digit wheels on the snappy spring through a subtle feathered clip, while gained or lost places open on the morph spring and close on the smooth spring. Typing cuts immediately (
0ms) so the caret stays synchronized. - Fit-to-width scaling: a
ResizeObserveranimates the display scale on the smooth spring when the formatted amount outgrows the shell. - Currency symbol slot: switching currencies rolls the symbol on the snappy spring while its slot width morphs smoothly to fit multi-character symbols.
- Limit refusal: exceeding
max(or stepping belowmin) kicks the amount sideways on a critically damped0.42sspring (velocity: ±160) and tints the range hint for1400ms. - Chip press: quick add chips compress on press to
motionOptions.pressScale(0.97by default); setmotionOptions.stagger(in ms) to cascade newly opened digit columns. - Reduced motion:
prefers-reduced-motion: reducedisables wheel travel, symbol rolls, scale animations, and kicks while keeping120msopacity crossfades.motion="none"makes all updates immediate (0ms).
theme accepts the core and control token groups, plus borderStrong, surfaceSunken, warning, radiusSm, popupRadius, popupPadding, itemHeight, itemPaddingX, itemPaddingY, itemRadius, fontFamilyDisplay, and five component tokens: height (--ui-money-input-height), menuDrop (--ui-money-input-menu-drop), menuWidth (--ui-money-input-menu-width), currencySize (--ui-money-input-currency-size), and fontSize (--ui-money-input-font-size).
Composition
MoneyInput is a leaf component. Its minor-unit amount (number | null) is host state at /fields/instance-<id>/value, and its ISO 4217 currency code is host state at /fields/instance-<id>/currency. Stored integer amounts and valid currency codes survive configuration edits. See Building with agents.
{
"type": "MoneyInput",
"props": {
"label": "Transfer amount",
"defaultCurrency": "USD",
"currencies": ["USD", "EUR", "GBP"],
"min": 100,
"max": 1000000,
"quickAdd": [25, 100, 500]
},
"children": []
}