Description
The InputMasked component uses the basic Input component, but with some additional masking functionality.
How it works
This component uses the basic Input but with a set of options and features.
You will either create your own mask, or use one of the provided once. There are also masks which change based on different locales (as_currency
or as_number
).
Accessibility
Screen readers will read also the mask before the user is entering the content. Also, the user will hear the mask during typing. This behavior can both have positive and negative side effects on the user. But overall, it works ok.
Both entering a comma or a dot will act as a decimal separator if decimals are enabled and one of the internal masks for numbers is used.
InputMode
NB: Please do not set inputMode="numeric"
or inputMode="decimal"
, because devices may or may not show a minus key (-
)!
The InputMasked component does handle soft keyboards (iOS and Android) by using either inputMode="numeric"
and inputMode="decimal"
depending on allowNegative
and allowDecimal
(getSoftKeyboardAttributes).
For iOS it additionally sets type="number"
during focus (InputModeNumber). This way the correct numeric soft keyboard is shown.
<InputMasked mask_options={{ allowNegative: false, }} />
Mask based on locale
The InputMasked component supports masks based on a given locale. The locale will be inherited from the Eufemia Provider if not given.
As of now, you can enable these masks by giving:
as_currency="EUR"
as_number={true}
You can still send in custom mask parameters to currency_mask={{ ... }}
or number_mask={{ ... }}
. But you can also make use of mask_options={{ ... }}
and just send in your extra options in there.
More details in the examples above.
Clean number values
If you use as_currency
or as_number
you have to always send in in a clean number without any mask (value="1234.50"
):
<InputMasked as_currency="EUR" value="1234.50" />