Skip to main content
Brand and assets
Build
Monitor and contribute
/
Component library
  • All components
  • Buttons & actions
  • Forms & inputs
    • Checkbox
    • ChoiceGroup
    • CurrencyInput
    • DateInput
    • FileInputZone
    • Filters
    • Form
    • MaskedTextInput
    • PasswordInput
    • Pill
    • Pill
    • Radio
    • SearchInput
    • SegmentedSlider
    • Select
    • Switch
    • TextArea
    • TextInput
  • Layout & containers
  • Overlays
  • Feedback & status
  • Data display
  • Typography
  • Accessibility
  • Contrib
  • Deprecated
  • Forms & inputs
  • CurrencyInput

CurrencyInput

Captures a money amount. The member types major units, the value is held in cents as an integer.

Health
Component health
Source
View on Github
Playground
No Example
Accessibility
unknown
Platform
Universal
  • Overview
  • Props

Input for a money amount. The user types in major units (1 234,50), and value / onChange use minor units (cents) as an integer (123450), or null when empty.

import { CurrencyInput } from "murray";

Accepts the TextInput props (label, error, helpText, placeholder, etc.) except prefix, suffix, type, inputMode, min, max and step, which the component owns. See the Props tab for the full list.

Usage​

Controlled​

Pass value and update it from onChange. Use this when the amount lives in your state or form library.

€

Stored value: 123450 cents

Uncontrolled​

Pass defaultValue and let the input keep its own state. onChange still receives every change in cents.

€

Last onChange: 123450 cents

Invalid text​

The user can type anything. Text that is not an amount (12abc, 12,5,0, 12,345 in EUR) emits onChange(null, { invalid: true }), stays as typed on blur, and shows an error until the user fixes it. Check invalid to block submit on optional fields, where null alone means empty. An error prop takes precedence over the built-in message.

Whole units​

wholeUnits accepts whole amounts only and shows no decimals. value stays in minor units, so 50 € is 5000. Typing decimals is invalid text.

€

Stored value: 5000000 cents

Suffix​

suffix adds text after the amount and its symbol, such as / month. Screen readers hear it after the currency name: "Allowance (euros / month)".

€ / month

$

/ month

Locales and currencies​

Pass currency from the data you edit (the company's or contract's currency), not from the user's locale: an ops person browsing in fr-FR can edit a Canadian amount in CAD. locale only decides how the number looks.

Everything else comes from Intl.NumberFormat:

  • Symbol and position: 1 234,50 € in fr-FR, $1,234.50 in en-CA, SAR 1,234.50 in en-SA. English locales with euros show €1,234.50, matching formatAmountWithCurrency.
  • Separators: decimal and thousands separators follow the locale.
  • Decimal places: from the currency. EUR, CAD and SAR all take 2, so values are in cents (halalas for SAR).

€

€

$

$

SAR

ر.س.

Typing behavior​

  • Thousands separators show only when the input is blurred. While focused the input shows 1234,50, so the cursor never jumps.
  • Spaces, group separators and the currency symbol carry no value. Letters, signs, a second decimal separator and decimals beyond the currency's precision make the text invalid; the error shows on blur, never while typing.
  • . and , both count as the decimal separator when the text has no locale decimal separator, because a phone's decimal key follows the device locale, not the app's. As a consequence, typing 1.234 in es-ES is invalid (three decimals), not one thousand.
  • Negative amounts are not supported.

Accessibility​

  • The accessible name adds the spoken currency after the label, so screen readers announce "Monthly allowance (euros)". This works with label, aria-label, aria-labelledby and title.
  • The visible symbol is aria-hidden, so it is not read twice.
  • Polite live regions announce new error messages, including the built-in one on blur ("Only numbers with up to 2 decimal places are allowed."), and blur rewriting the typed amount ("Amount updated to 12,50 €"). Blur that only adds thousands separators stays quiet. On mobile, announcements go through AccessibilityInfo.announceForAccessibility.

Usage in <Form>​

On web, Form.CurrencyInput stores the amount in cents in the Formik values. Invalid text fails validation even on an optional field, so it blocks submit, and shows the format error rather than a schema error such as "required".

€

€

Condensed theme​

For applications with condensed theme density, this component renders in a condensed style:

Error state​

€

Enter an amount above 0 €

Playground​

Loading...
tip
This component is universal, its usage is the same in murray and murray/mobile.

CurrencyInput props

NameTypeDefault ValueDescriptionUsage count
allowNegativebooleanundefinedfalseAccept a leading minus sign, such as `-12,50`, which makes `value` negative: `-1250` is -12,50 €.
aria-describedbystringundefinedId of an element outside the input that also describes it, such as an error shared by several inputs
aria-labelstringundefinedAccessibility label, only necessary when not associated with a label
aria-labelledbystringundefined
aria-requiredbooleanundefinedOverrides `aria-required` set by `required`, to mark the input as mandatory without the asterisk
autoFocusbooleanundefinedIf true, focuses the input on componentDidMount.The default value is false.
currency*stringISO 4217 code, such as `EUR`, `CAD` or `SAR`. Take it from the data you edit, not from the user's locale.
cursorCursorundefinedEnforce a cursor type
defaultValuenumbernullundefinednullUncontrolled initial amount in the minor unit of the currency.
disabledbooleanundefinedDisable input
enterKeyHint
6 possibilities"search""done""go""next""send"undefined
errorReactNodeContents of `InputError` component, if not set, error is not rendered.
focusedbooleanundefinedShow focus styles even when the input isn't focused, e.g. while a readonly input's picker is open
groupLabelReactNodeName of the group the input belongs to, such as the date its day field is part of. VoiceOver and TalkBack don't announce it when focus lands on the input, so on native it ends the input's accessible name, after `label`. Ignored without a `label`.
helpTextReactNodeContents of `InputHelp` component, if not set, description is not rendered.
idstringundefined
labelReactNode
localestringundefinedBCP 47 locale for separators and symbol position, such as `fr-FR` (French), `en-FR` (English in France), `fr-BE`, `nl-BE` (Dutch in Belgium), `es-ES` (Spanish), `fr-CA` (Canadian French), `en-CA` (Canadian English) or `ar-SA` (Arabic in Saudi Arabia). Defaults to the current i18n locale.
maxLengthnumberundefinedMaximum string length that the user can enter in UTF-16 code units
minLengthnumberundefinedMaximum string length that the user can enter in UTF-16 code units @platform web
namestringundefinedHtml input name @platform web
onChange
2 possibilities((value: number | null, details: { invalid: boolean; }) => void)undefined
Receives the amount in minor units (cents) on every change, `null` when cleared or invalid. `details.invalid` tells text that is not an amount, such as "12,5,0", apart from an empty input.
onPress
2 possibilities((event: GestureResponderEvent) => void)undefined
placeholderstringundefined
prefixPointerEvents
5 possibilities"none""auto""box-none""box-only"undefined
Sets pointer-events styles on the `prefix` element, `none` by default
readonlybooleanundefinedMake input readonly
render
2 possibilities((elements: { input: ReactNode; prefix?: ReactNode; suffix?: ReactNode; }, pseudoState: PseudoState) => ReactNode)undefined
Fully control how input, prefix and suffix are rendererd
renderPlaceholder(() => ReactNode)undefinedTo render a custom placeholder view when the field is empty
requiredbooleanundefinedAdds required attribute to the input and a red asterisk on the right side of label, `false` by default Determines whether the input should have `aria-required` attribute
suffixstringundefinedText after the amount and its symbol, such as `/ month`. Screen readers hear it after the currency name.
suffixPointerEvents
5 possibilities"none""auto""box-none""box-only"undefined
Sets pointer-events styles on the `suffix` element, `none` by default
sxPositionPropsundefinedPositioning properties
titlestringundefinedHtml input title @platform web
valuenumbernullundefinedControlled amount in the minor unit of the currency: `1250` is 12,50 €. `null` when empty.
wholeUnitsbooleanundefinedfalseAccept whole amounts only, such as `50` but not `50,50`. `value` stays in minor units: `5000` is 50 €.

Undocumented props

NameTypeDefault ValueDescriptionUsage count
onBlurany

Style API​

Use sx for one-off adjustments. It accepts these style keys:

alignSelfanimationaspectRatiobottomcursordisplayendflexflexBasisflexGrowflexShrinkheightinsetinsetInlineinsetInlineEndinsetInlineStartleftmarginmarginBottommarginHorizontalmarginInlinemarginInlineEndmarginInlineStartmarginLeftmarginRightmarginTopmarginVerticalmatrixmaxHeightmaxWidthminHeightminWidthopacityperspectivepositionrightrotaterotateXrotateYrotateZscalescaleXscaleYskewXskewYstarttoptransformtransformOriginwidthxyzIndex

Each can be overridden per breakpoint with:

$lg$ltLg$ltMd$ltSm$ltVs$ltXl$ltXxl$md$sm$vs$xl$xs$xxl
Edit this page
Previous
ChoiceGroup
Next
DateInput
  • Usage
    • Controlled
    • Uncontrolled
    • Invalid text
    • Whole units
    • Suffix
  • Locales and currencies
  • Typing behavior
  • Accessibility
  • Usage in <Form>
  • Condensed theme
  • Error state
  • Playground

€

Condensed theme