UI

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

Loading interactive preview…

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.

$5.00 to $500.00

API reference

These serializable arguments and defaults come directly from the component schema.

ArgumentType / defaultDescription
labelstringDefault: "Amount"Visible label and accessible name. Name the information asked for, in sentence case.
hideLabelbooleanDefault: falseHide the label visually when the context already names the field. It is still announced.
descriptionstring—Supporting text below the field, announced with it. Use it for format hints and constraints.
errorstring—Validation message from your application. Setting it marks the field invalid; the message is linked to the field and announced politely.
requiredbooleanDefault: falseMarks the field as required for assistive technology and shows an indicator. Your application validates the value.
readOnlybooleanDefault: falseThe value can be focused, selected, and copied, but not edited. It is still submitted with a form.
disabledbooleanDefault: falseUnavailable and removed from the tab order. A disabled field is not submitted with a form.
namestring—Native form field name, submitted with the value in a form.
defaultValueinteger | nullDefault: nullInitial 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.
defaultCurrencystringDefault: "USD"Initial ISO 4217 currency code, USD by default. It must appear in currencies.
currenciesstring[]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.
mininteger—Lowest amount in minor units; a blurred value below it shows a message and stays as typed until the host corrects it.
maxinteger—Highest amount in minor units; typing past it is refused with a sideways nudge and the range flashes.
stepinteger—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.
quickAddnumber[]Default: [10,50,100]Quick add chips in major units ($10, $50, $100 by default); at most 8. An empty array hides the chips.
localestring—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.
labelsobject—Reader-facing copy: the menu, chips and range messages.
variantoutline | soft | ghostDefault: "outline"Field surface: outline in forms, soft, or ghost inline.
sizesm | md | lgDefault: "md"Field height and text size.
recipestudio | softDefault: "studio"Visual treatment. Both recipes use the same interaction behavior.
themeMoneyInputTheme—Color mode, accent, and semantic tokens. See Theming for all keys and defaults.
motionnone | subtle | expressiveDefault: "subtle"Rolling digits, the refusal kick, the symbol roll and message copy. Reduced motion keeps short fades; none makes every change immediate.
motionOptionsobject—Fine tune the digit roll: the column stagger and the chip press scale.
dirltr | rtl—Reading direction. Omit it to inherit the page direction.

React integration

PropPurpose
value, onValueChangeControlled minor-unit amount (number | null). Callback receives (value, details).
currency, onCurrencyChangeControlled ISO 4217 currency code (string) and selection callback.
refRef to the native <input> element.
portalContainerCustom portal target for the currency menu (defaults to enclosing layer or body).
presetApplication defaults (such as locale, labels, quickAdd), overridden by props.
tokensCSS custom properties (--ui-*) applied after the typed theme on root and portal.
className, styleApplied to the root field element, which carries the resolved tokens.
Native attributesForwarded to <input> (onBlur, onKeyDown, autoFocus, aria-*).

MoneyInputDetails provides { currency: string, major: number | null, formatted: string } on every change.

Keyboard & accessibility

KeyInteraction
ArrowUp, ArrowDownAdd or subtract one step (defaults to one major unit) in the amount input.
Shift + arrows, PageUp/PageDownAdd or subtract ten step units.
EnterSettle the typed draft and pad missing fraction digits.
Backspace, DeleteCrossing 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, EndMove 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 ResizeObserver animates 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 below min) kicks the amount sideways on a critically damped 0.42s spring (velocity: ±160) and tints the range hint for 1400ms.
  • Chip press: quick add chips compress on press to motionOptions.pressScale (0.97 by default); set motionOptions.stagger (in ms) to cascade newly opened digit columns.
  • Reduced motion: prefers-reduced-motion: reduce disables wheel travel, symbol rolls, scale animations, and kicks while keeping 120ms opacity 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": []
}

On this page