Money Input
Currency amount field that groups digits as you type, follows the locale and stores an integer count of minor units.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
value | string | — | The amount as an integer count of minor units ('1050' for 10.50 USD), or an empty string. |
currency | string | USD | ISO 4217 code of the currency (USD, EUR, JPY). Decides the symbol and the minor-unit digits. |
currencies | string[] | [] | Currencies the user may pick from, as ISO codes. With two or more a picker is shown. As an attribute, separated by semicolons. |
currency-display | CurrencyDisplay | symbol | How the currency is written next to the amount: symbol (CA$), narrowSymbol ($) or code (CAD). |
locale | string | — | BCP 47 locale for separators and the symbol position. Empty uses the nearest lang, then the browser's language. |
min | string | — | Smallest valid value, in minor units. A negative min lets the user type a minus sign. |
max | string | — | Largest valid value, in minor units. |
name | string | — | Form field name of the value. |
currency-name | string | — | Form field name of the currency code. Empty submits the value only. |
autocomplete | string | — | Browser autocomplete hint, such as transaction-amount. |
placeholder | string | — | Text shown while the field is empty. Empty shows zero in the currency's format (0.00). |
required | boolean | false | Requires an amount before the form can be submitted. |
readonly | boolean | false | Prevents editing while keeping the value in form submission. |
disabled | boolean | false | Prevents interaction and excludes the value from form submission. |
error | boolean | false | Applies the visual error state and sets aria-invalid. |
help | string | — | Helper text shown below the field. |
error-text | string | — | Message shown below the field while error is set. |
aria-label | string | null | null | Accessible name forwarded to the amount field. |
Slots
| Name | Description |
|---|---|
symbol | Replaces the currency symbol drawn next to the amount. |
chevron-icon | Replaces the chevron of the currency picker. |
supporting-text | Rich helper content below the field. help and error-text are plain-text shortcuts. |
Events
| Name | Type | Description |
|---|---|---|
change | Event | The value was committed: the field lost focus or Enter was pressed after an edit, or a picked currency changed the value. |
currency-change | CustomEvent<MoneyInputCurrencyChangeDetail> | The user picked another currency. Does not bubble; listen on the element. |
input | InputEvent | Re-dispatched from the amount field on every edit; also fired when a picked currency changes the value. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-money-input--min-height | pixel | 36px | |
--c2-money-input--border | border | 1px solid #bcbcc6 | |
--c2-money-input--border-radius | border-radius | 6px | |
--c2-money-input--color | color | #18181b | |
--c2-money-input--background | color | #ffffff | |
--c2-money-input--font-size | font-size | 14px | |
--c2-money-input--font-family | font-family | inherit | |
--c2-money-input--line-height | pixel | 20px | |
--c2-money-input__value--padding | padding | 6px 12px | Space around the symbol and the amount. |
--c2-money-input__value--gap | pixel | 6px | Space between the symbol and the amount. |
--c2-money-input__input--text-align | text-align | left | right lines amounts up in a column of fields. |
--c2-money-input__input--font-variant-numeric | font-variant-numeric | tabular-nums | |
--c2-money-input__input--font-weight | font-weight | 400 | |
--c2-money-input__placeholder--color | color | #71717a | |
--c2-money-input__hover--border | border | 1px solid #a1a1aa | |
--c2-money-input__focus--border | border | 1px solid rgb(2, 101, 220) | |
--c2-money-input__focus--outline | outline | none | |
--c2-money-input__focus--outline-offset | pixel | 0px | |
--c2-money-input__error--border | border | 1px solid #dc2626 | |
--c2-money-input__error__focus--outline | outline | none | |
--c2-money-input__read-only--background | color | #fafafa | |
--c2-money-input__disabled--opacity | opacity | 0.38 | |
--c2-money-input__symbol--display | display | inline | none hides the currency symbol. |
--c2-money-input__symbol--color | color | #71717a | |
--c2-money-input__symbol--font-size | font-size | 14px | |
--c2-money-input__symbol--font-weight | font-weight | 400 | |
--c2-money-input__picker--padding | padding | 0 30px 0 10px | Space around the code in the currency picker; the right side holds the chevron. |
--c2-money-input__picker--color | color | #18181b | |
--c2-money-input__picker--background | color | transparent | |
--c2-money-input__picker--font-size | font-size | 14px | |
--c2-money-input__picker--font-weight | font-weight | 500 | |
--c2-money-input__picker--border-left | border | 1px solid #e4e4e7 | Line between the amount and the currency picker. |
--c2-money-input__picker__hover--background | color | #f4f4f5 | |
--c2-money-input__picker__focus--outline | outline | 2px solid rgba(2, 101, 220, 0.4) | Keyboard focus ring of the currency picker. |
--c2-money-input__icon--size | pixel | 16px | |
--c2-money-input__icon--color | color | #71717a | |
--c2-money-input__supporting-text--gap | pixel | 4px | |
--c2-money-input__supporting-text--font-size | font-size | 12px | |
--c2-money-input__supporting-text--line-height | pixel | 16px | |
--c2-money-input__supporting-text--color | color | #71717a | |
--c2-money-input__supporting-text__error--color | color | #dc2626 | |
Text and languages
The text the component shows, in English. It shows another language when the app adds one with addTranslations, under money-input, and the nearest lang asks for it; any message not translated stays in English. {0}, {1}… stand for the values a message carries. Languages guide.
| Key | English | Values |
|---|---|---|
currency | Currency | — |
valueMissing | Enter an amount. | — |
rangeUnderflow | Enter {0} or more. | {0} min |
rangeOverflow | Enter {0} or less. | {0} max |