Mask Input
A text input that fits what is typed to a pattern, for postcodes, IBANs, tax IDs, expiry dates and other fixed formats.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
mask | string | — | The pattern: 9 digit, a letter, A upper-case letter, * letter or digit, X upper-case letter or digit,
\ escapes the next character, ? makes the rest optional, [ ] wrap an optional group. Anything else is a
literal. Empty, the field takes any text, like a plain input. |
value | string | — | The typed characters, without the literals; with include-literals, the formatted text. Setting it fits the new
text to the mask. Setting the attribute after the user has typed no longer updates it, like a native input. |
include-literals | boolean | false | value and the submitted form value include the mask's literals (12/34 rather than 1234). |
slot-char | string | _ | Character shown in the positions still to fill. |
name | string | — | Form field name: the value is submitted with the form under this name. |
placeholder | string | — | Text shown while the field is empty and does not have focus. |
aria-label | string | null | null | Accessible name of the field. Defaults to the placeholder. |
autocomplete | string | — | Autofill hint, e.g. postal-code, cc-exp or tel-national. |
inputmode | string | — | Virtual keyboard to show. When unset, numeric for a mask of digits only, otherwise text. |
required | boolean | false | The field must not be empty. |
disabled | boolean | false | Disables the field. |
readonly | boolean | false | The value can be selected and copied but not edited. |
error | boolean | false | Marks the field invalid and shows error-text in place of help. |
error-text | string | — | Message shown while error is set. |
help | string | — | Helper text under the field. |
Slots
| Name | Description |
|---|---|
prefix-icon | Icon or short adornment text at the start of the field. |
suffix-icon | Icon or adornment at the end of the field. |
supporting-text | Rich helper content below the field. help and error-text are the plain-text shortcuts. |
Events
| Name | Type | Description |
|---|---|---|
complete | CustomEvent<MaskInputCompleteDetail> | The user filled the last required position of the mask. |
change | Event | Fired when an edited value is committed (blur or Enter), like an input's change. |
input | InputEvent | Re-dispatched from the inner input after each edit; value is already updated. |
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-mask-input--min-height | pixel | 36px | |
--c2-mask-input--padding | padding | 6px 12px | |
--c2-mask-input--gap | pixel | 8px | Space between the icons and the text. |
--c2-mask-input--color | color | #18181b | |
--c2-mask-input--background | color | #ffffff | |
--c2-mask-input--border | border | 1px solid #bcbcc6 | |
--c2-mask-input--border-radius | border-radius | 6px | |
--c2-mask-input--font-size | font-size | 14px | |
--c2-mask-input--font-family | font-family | — | |
--c2-mask-input--font-variant-numeric | font-variant-numeric | tabular-nums | Keeps digits one width, so the mask hint does not shift while typing. |
--c2-mask-input--letter-spacing | letter-spacing | normal | |
--c2-mask-input__placeholder--color | color | #71717a | |
--c2-mask-input__slot--color | color | #a1a1aa | Colour of the rest of the mask shown behind the text. |
--c2-mask-input__hover--border | border | 1px solid #a1a1aa | |
--c2-mask-input__focus--border | border | 1px solid rgb(2, 101, 220) | |
--c2-mask-input__focus--background | color | — | |
--c2-mask-input__focus--outline | outline | none | |
--c2-mask-input__error--border | border | 1px solid #dc2626 | |
--c2-mask-input__read-only--border | border | 1px solid #e4e4e7 | |
--c2-mask-input__read-only--background | color | #fafafa | |
--c2-mask-input__disabled--opacity | opacity | 0.38 | |
--c2-mask-input__icon--size | pixel | 16px | |
--c2-mask-input__icon--color | color | #71717a | |
--c2-mask-input__supporting-text--gap | pixel | 4px | Space between the field and the helper line. |
--c2-mask-input__supporting-text--font-size | font-size | 12px | |
--c2-mask-input__supporting-text--line-height | pixel | 16px | |
--c2-mask-input__supporting-text--color | color | #71717a | |
--c2-mask-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 mask-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 |
|---|---|---|
format | Format: {0} | {0} format |
incomplete | Enter a value in the format {0}. | {0} format |