Form
InputMask
A text box that types into a pattern, such as a phone or a date, filling in the literals for you. InputText and AutoComplete take the same masks.
WAI-ARIA tested
Import
main.ts
import { InputMask } from '@vitral/vue';Basic
Value: —
Unmasked value
v-model: —
A pattern that follows the value
A list shows the first pattern with room for what has been typed: the CPF turns into a CNPJ at the twelfth digit, and back when one is deleted. A function receives the characters typed so far and returns the pattern.
Value: —
Value: —
Masks as values
A mask object carries the pattern with its settings, so it is defined once and gives the same box in InputMask, InputText and AutoComplete. A setting on the field wins over the one in the object.
Value: —
Value: —
Value: —
Slot characters and optional parts
Sizes and states
API
Read from packages/vue/src/components/InputMask/types.ts, so it says what the component actually accepts.
Props
| Name | Type | Description |
|---|---|---|
| size | Size | — |
| variant | InputVariant | Defaults to the plugin's `inputVariant`. |
| invalid | boolean | — |
| disabled | boolean | — |
| readonly | boolean | — |
| fluid | boolean | — |
| mask | MaskProp | The pattern: `9` takes a digit, `a` a letter, `*` either; anything after `?` is optional; every other character is typed for the reader. A list of patterns lets the value take more than one shape: the first with room for what has been typed is shown, so `['999.999.999-99', '99.999.999/9999-99']` is a CPF that turns into a CNPJ at the twelfth digit, and back again when one is deleted. A function receives the characters typed so far, without literals, and returns the pattern to show. An object carries the pattern with its settings, so one mask can be defined once and passed to any field. |
| slotChar | string | What an empty slot shows: one character, or a string as long as the mask (`'mm/dd/yyyy'`). Defaults to `_`. |
| autoClear | boolean | Clear an unfinished value when the box loses focus. Defaults to true. |
| unmask | boolean | v-model receives only the typed characters, without the literals. |
| definitions | MaskDefinitions | Extra slot characters, each with the characters it accepts. |
Plus pt, dt and unstyled from BaseProps, see pass-through and unstyled mode.
Emits
| Event | Payload | Description |
|---|---|---|
| complete | event: { originalEvent: Event; value: string } | Every required slot is filled. |
| focus | event: FocusEvent | — |
| blur | event: FocusEvent | — |