Input mask
vig-input-mask
import { InputMask, MASK_DIGIT, MASK_LETTER, MASK_ALPHANUMERIC } from '@vigdx/ui/input-mask';Basic
mask pattern and bind [(value)] . Literals appear as the user types, Backspace skips over them, and the value holds the typed characters only ( 5551234567 ). In a pattern 9 is a digit, a a letter, * either, and \ makes the next character literal. Escape token characters you mean literally: in +90 (999) the 9 is a slot, so write +\90 (999) . The keyboard follows the mask: digits only open the digit pad.
Value: ""
Placeholder character, formatted value and completion
placeholderChar="_" shows the whole pattern while the field is focused or filled. valueFormat="formatted" makes the value the text as shown ( 31/12/19 ) instead of the raw characters. An incomplete value is kept, never cleared: validate it with the form. (completed) fires when the last slot is filled.
DD/MM/YYYY
Date: "" · Plate: ""
Custom slots
MaskSlot objects: { accepts: (char) => boolean, transform?, inputMode? } . MASK_DIGIT , MASK_LETTER and MASK_ALPHANUMERIC are the pattern's slots. Here letters are upper-cased as they are typed.
Value: ""
Icons, label position, states and sizes
vigInputPrefix and vigInputSuffix slots of vig-input work here too. labelPosition , hideLabel , disabled , readonly and size behave as in the other text fields.
Signal Forms
vig-input-mask implements FormValueControl<string> for [formField] . With the raw value, a complete phone number is 10 characters long, so minLength checks completeness. A value set from outside may be raw or formatted ( +1 (555) 123-4567 is read through its literals); it is written back in the field's own form, which leaves Reactive Forms and ngModel controls pristine but makes a Signal Forms field dirty.
Valid: no
Reactive Forms
VigValueAccessor next to the component to use formControlName , [formControl] or ngModel .
Value: "34000"
How editing works
- Every edit is read from the
beforeinputevent, applied to the mask and written back with the caret in place, so nothing jumps in Chromium, Firefox or WebKit. Edits a browser does not let the field cancel (some Android keyboards, word deletions, cut, spell-check and autofill) are read back from theinputevent instead. - Typing in the middle moves the following characters along; deleting moves them back. Backspace and Delete skip over literals to the nearest character. A full mask refuses more characters instead of dropping the last one.
- Paste and drop take formatted text (
(555) 123-4567) or plain characters, and drop whatever overflows. Autofill fills the whole value. - IME compositions (Japanese, Chinese, Korean keyboards; Android word suggestions) are left alone until they end, then applied; full-width and Arabic-Indic digits become ASCII.
- Undo and redo (Ctrl+Z, Ctrl+Shift+Z or Ctrl+Y; ⌘Z and ⇧⌘Z on Apple devices, on any keyboard layout) step through the field's own history, and fire
(completed)when they bring back a complete value. The browser's Edit menu and shake to undo do not reach it: the field rewrites every edit, which the browser's own undo history does not record. - In masks that mix letters and digits, an edit that would move characters into slots that reject them is refused: typing
0before34Ain99 aaa 999does nothing, and deleting a letter ofaa99selects it instead, so typing replaces it. Nothing after the caret is ever lost; select text to type over it. - A character the mask rejects, typed or pasted over a selection, leaves the selection as it is. Cut and drag remove exactly what they select, literals included, without taking a character next to them.
Styling hooks
Internal elements carry a stable data-part and the component's data-scope; both are public API, so removing one is a breaking change. Select a part by both, e.g. [data-scope="input-mask"][data-part="field"] { … }: the pair stays within this component when kit components nest, and also reaches parts in overlay panels, which render outside the host. State is exposed through aria-* and, where listed, a data-state; literal values are checked by the API gate, values computed from the component's state follow its documented types. Other data-* attributes listed below (such as data-opening while an overlay animates) are API too. See Customizing.
Scope: [data-scope="input-mask"]
| Part | Element | data-state |
|---|---|---|
field | — | |
label | — | |
prefix | [vigInputPrefix] slot. | — |
input | <input> (always dir="ltr" ). | — |
suffix | [vigInputSuffix] slot. | — |
hint | vig-hint (a display: contents host; style its text part). | — |
disabled-reason | vig-hint with the disabled reason ( display: contents ). | — |
error | vig-field-error (a display: contents host; style its message part). | — |
Accessibility
- A native
<input type="text">named by a real<label>; hint, disabled reason and error are linked througharia-describedby. Describe the expected format in thehintor aplaceholderexample: screen readers read the value, not the pattern. inputmodefollows the mask, and autocorrect, auto-capitalization and spell check are off. Setautocomplete(tel-national,postal-code,cc-number…) so browsers can fill the field (WCAG 1.3.5).- The text always runs left to right (
dir="ltr"), also on RTL pages, so phone numbers and codes keep their order; it aligns to the page's start, where the label and prefix sit.
API
InputMask
vig-input-maskA text field that formats what is typed into a fixed pattern — phone numbers, IBANs, codes, dates typed as digits:
Example :<vig-input-mask label="Phone" mask="(999) 999-9999" autocomplete="tel-national" [(value)]="phone" />In a pattern 9 is a digit, a a letter, * either and \ escapes a
literal; pass an array of literals and MaskSlots for custom slots. The
value is the typed characters only (5551234567); valueFormat="formatted"
makes it the text as shown. An incomplete value is kept, never cleared:
validate it with the form ((completed) fires once every slot is filled).
Editing goes through beforeinput (cancelled and applied by the field) and
falls back to reading the input event's change, so mobile keyboards, IME
compositions, paste, drop, autofill and undo all keep the caret in place.
The text always runs left to right (dir="ltr"), also on RTL pages.
| Name | Type | Default | Description |
|---|---|---|---|
autocomplete | string | undefined | undefined | Native |
dirty | boolean | false | — |
disabled | boolean | false | — |
disabledReasons | readonly WithOptionalFieldTree<DisabledReason>[] | [] | — |
errorMessages | Record<string, string> | — | — |
errors | readonly ValidationError.WithOptionalFieldTree[] | [] | — |
hidden | boolean | false | — |
hideLabel | boolean | false | Visually hides the label, which still names the field; pair it with a placeholder. |
hint | string | undefined | undefined | — |
invalid | boolean | false | — |
label | string | — | — |
labelPosition | LabelPosition | 'float' |
|
mask | Mask | — | The pattern ( |
name | string | '' | — |
pending | boolean | false | — |
placeholder | string | undefined | undefined | Native placeholder of the empty field, e.g. an example value. |
placeholderChar | string | undefined | undefined | Shows the whole pattern while the field is focused or filled, with this
character in the empty slots (e.g. |
readonly | boolean | false | — |
required | boolean | false | — |
size | FieldSize | 'md' | — |
touched | boolean | false | — |
value | string | '' | — |
valueFormat | InputMaskValueFormat | 'raw' |
|
| Name | Payload | Description |
|---|---|---|
completed | string | Emits the value when the user fills the last empty slot. |
touch | void | — |
valueChange | string | — |
| Signature | Description |
|---|---|
focus(options?: FocusOptions): void | Moves focus to the control's interactive element (the input, or the
trigger of a popup control). Signal Forms calls it through
|
reset(): void | Drops the undo history; see |
VigValueAccessor
Bridges the vigdx form fields to Reactive Forms (formControl,
formControlName) and template-driven forms (ngModel). Import it next to
the component; Signal Forms ([formField]) need no accessor.
| Signature | Description |
|---|---|
registerOnChange(fn: (value: unknown) => void): void | — |
registerOnTouched(fn: () => void): void | — |
setDisabledState(disabled: boolean): void | — |
writeValue(value: unknown): void | — |