# @commercetools-uikit/money-field

> A controlled input component for money values with validation states and a label.

Latest version **20.6.8** (published 2026-11-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install @commercetools-uikit/money-field
pnpm add @commercetools-uikit/money-field
yarn add @commercetools-uikit/money-field
bun add @commercetools-uikit/money-field
```

## Health

**Score 65/100 (B)** — status: active.

Positive: esm support; no vulnerabilities; has provenance; recently updated; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 20.6.8 |
| Published | 2026-11-23 |
| First published | 2019-11-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 15 |
| Unpacked size | 54.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 154 |
| Maintainers | emmenko, commercetools-admin, tdeekens |
| Keywords | javascript, typescript, design-system, react, uikit |

## Links

- npm: https://www.npmjs.com/package/@commercetools-uikit/money-field
- Repository: https://github.com/commercetools/ui-kit
- Homepage: https://uikit.commercetools.com
- Issues: https://github.com/commercetools/ui-kit/issues
- npm.io page: https://npm.io/package/@commercetools-uikit/money-field

## Dependencies (15)

- [lodash](https://npm.io/package/lodash.md) 4.18.1
- [react-intl](https://npm.io/package/react-intl.md) ^7.1.4
- [react-select](https://npm.io/package/react-select.md) 5.10.2
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.20.13
- [@emotion/react](https://npm.io/package/@emotion/react.md) ^11.10.5
- [@emotion/styled](https://npm.io/package/@emotion/styled.md) ^11.10.5
- [@babel/runtime-corejs3](https://npm.io/package/@babel/runtime-corejs3.md) ^7.20.13
- [@commercetools-uikit/utils](https://npm.io/package/@commercetools-uikit/utils.md) ^20.6.8
- [@commercetools-uikit/spacings](https://npm.io/package/@commercetools-uikit/spacings.md) ^20.6.8
- [@commercetools-uikit/constraints](https://npm.io/package/@commercetools-uikit/constraints.md) ^20.6.8
- [@commercetools-uikit/field-label](https://npm.io/package/@commercetools-uikit/field-label.md) ^20.6.8
- [@commercetools-uikit/money-input](https://npm.io/package/@commercetools-uikit/money-input.md) ^20.6.8
- [@commercetools-uikit/field-errors](https://npm.io/package/@commercetools-uikit/field-errors.md) ^20.6.8
- [@commercetools-uikit/design-system](https://npm.io/package/@commercetools-uikit/design-system.md) ^20.6.8
- [@commercetools-uikit/field-warnings](https://npm.io/package/@commercetools-uikit/field-warnings.md) ^20.6.8

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 20.6.8 (latest) — 2026-11-23
- 0.0.0-canary-20261123143223 (canary) — 2026-11-23
- 0.0.0-FEC-938-ui-kit-post-pnpm-tooling-polish-catalogs-bundlewatch-bundlesize-20260518121756 (FEC-938-ui-kit-post-pnpm-tooling-polish-catalogs-bundlewatch-bundlesize) — 2026-05-18
- 0.0.0-migration-pnpm-20260513114959 (migration-pnpm) — 2026-05-13
- 0.0.0-CRAFT-2040-rich-text-input-destroys-hyperlink-tag-20260219190637 (CRAFT-2040-rich-text-input-destroys-hyperlink-tag) — 2026-02-19
- 0.0.0-fec-155-react-19-20250528075244 (fec-155-react-19) — 2025-05-28
- 0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339 (FCT-1500-adjust-legacy-css-reset) — 2025-05-27
- 0.0.0-SUPPORT-32352-de-ch-money-input-20250509174254 (SUPPORT-32352-de-ch-money-input) — 2025-05-09
- 0.0.0-main-20250115172531 (main) — 2025-01-15
- 0.0.0-preview-fec-155-react-19-20250113184401 (preview-fec-155-react-19) — 2025-01-13
- 0.0.0-preview-test-icon-entrypoints-20241212201418 (preview-test-icon-entrypoints) — 2024-12-12
- 0.0.0-preview-test-icon-pure-annotations-20241211181046 (preview-test-icon-pure-annotations) — 2024-12-11
- 0.0.0-preview-test-icon-bundle-20241210182318 (preview-test-icon-bundle) — 2024-12-10
- 0.0.0-preview-test-canary-preview-20241204111237 (preview-test-canary-preview) — 2024-12-04
- 0.0.0-preview-FCT-1187-20241024123200 (preview) — 2024-10-24
- … 1243 more at https://npm.io/package/@commercetools-uikit/money-field/versions

## README

<!-- THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -->
<!-- This file is created by the `pnpm generate-readme` script. -->

# MoneyField

## Description

A controlled input component for money values with validation states and a label.

## High Precision Money Values

The `MoneyField` component always operates on a value consisting of

```js
{ amount: String, currencyCode: String }
```

The amount can have an arbitrary precision. When the precision of the amount exceeds the precision of that currency, then that Money Value is referred to as being "high precision".

> ⚠️ The `MoneyField` will allow high precision money values by default. If you want to discourage them, you need to add validation as shown in the example below, or the Examples/Forms story.

## Installation

```
pnpm add @commercetools-uikit/money-field
```

```
npm --save install @commercetools-uikit/money-field
```

Additionally install the peer dependencies (if not present)

```
pnpm add react
```

```
npm --save install react
```

## Usage

```jsx
import MoneyField from '@commercetools-uikit/money-field';

const Example = () => (
  <MoneyField
    title="Price"
    value={{ amount: '20', currencyCode: 'EUR' }}
    onChange={(event) => alert(event.target.value)}
    currencies={['EUR', 'USD']}
  />
);

export default Example;
```

## Properties

| Props                     | Type                                                                                                  | Required | Default   | Description                                                                                                                                                                                                                                                           |
| ------------------------- | ----------------------------------------------------------------------------------------------------- | :------: | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `id`                      | `string`                                                                                              |          |           | Used as HTML id property. An id is auto-generated when it is not specified.                                                                                                                                                                                           |
| `horizontalConstraint`    | `union`<br/>Possible values:<br/>`, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto'` |          | `'scale'` | Horizontal size limit of the input fields.                                                                                                                                                                                                                            |
| `errors`                  | `Record`                                                                                              |          |           | A map of errors. Error messages for known errors are rendered automatically.&#xA;<br />&#xA;Unknown errors will be forwarded to `renderError`                                                                                                                         |
| `warnings`                | `Record`                                                                                              |          |           | A map of warnings. Warning messages for known warnings are rendered automatically.&#xA;<br/>&#xA;Unknown warnings will be forwarded to renderWarning.                                                                                                                 |
| `renderError`             | `Function`<br/>[See signature.](#signature-rendererror)                                               |          |           | Called with custom errors. This function can return a message which will be wrapped in an ErrorMessage. It can also return null to show no error.                                                                                                                     |
| `renderWarning`           | `Function`<br/>[See signature.](#signature-renderwarning)                                             |          |           | Called with custom warnings, as renderWarning(key, warning). This function can return a message which will be wrapped in a WarningMessage.&#xA;<br />&#xA;It can also return null to show no warning.                                                                 |
| `isRequired`              | `boolean`                                                                                             |          |           | Indicates if the value is required. Shows an the "required asterisk" if so.                                                                                                                                                                                           |
| `touched`                 | `Object`<br/>[See signature.](#signature-touched)                                                     |          |           | Indicates whether the `currencyCode` or `amount` fields were touched.&#xA;<br />&#xA;Errors will only be shown when the field was touched.                                                                                                                            |
| `isTouched`               | `unknown`                                                                                             |          |           |                                                                                                                                                                                                                                                                       |
| `autoComplete`            | `string`                                                                                              |          |           | Used as HTML `autocomplete` property                                                                                                                                                                                                                                  |
| `name`                    | `string`                                                                                              |          |           | The prefix used to create a HTML `name` property for the amount input field (`${name}.amount`) and the currency dropdown (`${name}.currencyCode`).                                                                                                                    |
| `value`                   | `Object`<br/>[See signature.](#signature-value)                                                       |    ✅    |           | Value of the input. Consists of the currency code and an amount. `amount` is a string representing the amount. A dot has to be used as the decimal separator.                                                                                                         |
| `currencies`              | `Array: string[]`                                                                                     |          |           | List of possible currencies. When not provided or empty, the component renders a label with the value's currency instead of a dropdown.                                                                                                                               |
| `placeholder`             | `string`                                                                                              |          |           | Placeholder text for the amount input                                                                                                                                                                                                                                 |
| `onBlur`                  | `Function`<br/>[See signature.](#signature-onblur)                                                    |          |           | Called when input is blurred                                                                                                                                                                                                                                          |
| `onFocus`                 | `Function`<br/>[See signature.](#signature-onfocus)                                                   |          |           | Called when input is focused                                                                                                                                                                                                                                          |
| `isDisabled`              | `boolean`                                                                                             |          |           | Indicates that the input cannot be modified (e.g not authorized, or changes currently saving).                                                                                                                                                                        |
| `isReadOnly`              | `boolean`                                                                                             |          |           | Indicates that the field is displaying read-only content                                                                                                                                                                                                              |
| `isAutofocussed`          | `boolean`                                                                                             |          |           | Focus the input on initial render                                                                                                                                                                                                                                     |
| `onChange`                | `Function`<br/>[See signature.](#signature-onchange)                                                  |          |           | Called with the event of the input or dropdown when either the currency or the amount have changed.                                                                                                                                                                   |
| `menuPortalTarget`        | `ReactSelectProps['menuPortalTarget']`                                                                |          |           | Dom element to portal the currency select menu to&#xA;<br>&#xA;[Props from React select was used](https://react-select.com/props)                                                                                                                                     |
| `menuPortalZIndex`        | `number`                                                                                              |          |           | z-index value for the currency select menu portal&#xA;<br>&#xA;Use in conjunction with `menuPortalTarget`                                                                                                                                                             |
| `menuShouldBlockScroll`   | `ReactSelectProps['menuShouldBlockScroll']`                                                           |          |           | whether the menu should block scroll while open&#xA;<br>&#xA;[Props from React select was used](https://react-select.com/props)                                                                                                                                       |
| `title`                   | `union`<br/>Possible values:<br/>`string , ReactNode`                                                 |    ✅    |           | Title of the label                                                                                                                                                                                                                                                    |
| `hint`                    | `union`<br/>Possible values:<br/>`string , ReactNode`                                                 |          |           | Hint for the label. Provides a supplementary but important information regarding the behaviour of the input (e.g warn about uniqueness of a field, when it can only be set once), whereas `description` can describe it in more depth. Can also receive a `hintIcon`. |
| `description`             | `union`<br/>Possible values:<br/>`string , ReactNode`                                                 |          |           | Provides a description for the title.                                                                                                                                                                                                                                 |
| `onInfoButtonClick`       | `Function`<br/>[See signature.](#signature-oninfobuttonclick)                                         |          |           | Function called when info button is pressed.&#xA;<br />&#xA;Info button will only be visible when this prop is passed.                                                                                                                                                |
| `hintIcon`                | `ReactElement`                                                                                        |          |           | Icon to be displayed beside the hint text.&#xA;<br />&#xA;Will only get rendered when `hint` is passed as well.                                                                                                                                                       |
| `hasHighPrecisionBadge`   | `boolean`                                                                                             |          |           | Shows high precision badge in case current value uses high precision.                                                                                                                                                                                                 |
| `isCurrencyInputDisabled` | `boolean`                                                                                             |          |           | Indicates that the currency input cannot be modified.                                                                                                                                                                                                                 |

## Signatures

### Signature `renderError`

```ts
(key: string, error?: boolean) => ReactNode;
```

### Signature `renderWarning`

```ts
(key: string, warning?: boolean) => ReactNode;
```

### Signature `touched`

```ts
{
  amount?: boolean;
  currencyCode?: boolean;
}
```

### Signature `value`

```ts
{
  amount: string;
  currencyCode: TCurrencyCode;
}
```

### Signature `onBlur`

```ts
(event: TCustomEvent) => void
```

### Signature `onFocus`

```ts
(event: TCustomEvent) => void
```

### Signature `onChange`

```ts
(event: TCustomEvent) => void
```

### Signature `onInfoButtonClick`

```ts
() => void
```

## `data-*` props

The component further forwards all `data-` attributes to the underlying `input` component.

## `errors`

This object is a key-value map. The `renderError` prop will be called for each entry with the key and the value. The return value will be rendered inside an `ErrorMessage` component underneath the input.

The `MoneyField` supports some errors out of the box. Return `undefined` from `renderError` for these and the default errors will be shown instead. This prevents consumers from having to reimplement the same error messages for known errors while still keeping the flexibility of showing custom error messages for them.

When the `key` is known, and when the value is truthy, and when `renderError` returned `undefined` for that error entry, then the `MoneyField` will render an appropriate error automatically.

Known error keys are:

- `missing`: tells the user that this field is required but no value was provided

## Main Functions and use cases are:

- Getting monetary value input with a currency from users (with cent precision or high precision)

## Static methods

### `MoneyField.toFieldErrors`

Use this function to convert the Formik `errors` object type to our custom field errors type. This is primarily useful when using TypeScript.

```ts
type FormValues = {
  myField: string;
};

<MoneyField
  // ...
  name="my-field"
  errors={MoneyField.toFieldErrors<FormValues>(formik.errors).myField}
/>;
```

---
_Source: https://npm.io/package/@commercetools-uikit/money-field · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
