Vitral 0.2.18
Form

InputText

A single-line text box whose attributes land on the native input, with prefix and suffix content, a clear button and an optional mask.

Import

main.ts
import { InputText } from '@vitral/vue';

Basic

Typed: —
<script setup lang="ts">import { InputText, Label, StackPanel } from '@vitral/vue';import { ref } from 'vue'; const name = ref('');</script> <template>    <StackPanel spacing="0.375rem" style="min-width: 16rem">        <Label for="it-name">Name</Label>        <InputText id="it-name" v-model="name" placeholder="Your name" aria-describedby="it-name-hint" />        <small id="it-name-hint" style="color: var(--vt-text-muted-color)">Typed: {{ name || '—' }}</small>    </StackPanel></template>

Adornments and clear button

Content inside the field on either side, and the clear button.

R$BRL
<script setup lang="ts">import { Icon, InputText, Label, StackPanel } from '@vitral/vue';import { ref } from 'vue'; const email = ref('ada@example.com');const price = ref('1299.90');</script> <template>    <StackPanel orientation="horizontal" spacing="0.75rem" align="start" wrap>        <StackPanel spacing="0.375rem" style="min-width: 16rem">            <Label for="it-email">Email</Label>            <InputText id="it-email" v-model="email" type="email" clearable>                <template #prefix><Icon icon="user" /></template>            </InputText>        </StackPanel>        <StackPanel spacing="0.375rem" style="min-width: 16rem">            <Label for="it-price">Price</Label>            <InputText id="it-price" v-model="price" inputmode="decimal">                <template #prefix>R$</template>                <template #suffix>BRL</template>            </InputText>        </StackPanel>    </StackPanel></template>

Masks

`mask` types into a pattern, as InputMask does, keeping the adornments and the clear button. It takes a pattern, a list, a function, or a mask object.

Value: —
Value: —
Value: —
Value: —
<script setup lang="ts">import { Icon, InputText, Label, StackPanel, type MaskOptions } from '@vitral/vue';import { ref } from 'vue'; // The old plate until a letter comes fifth, then the Mercosul one, in capitals.const plateMask: MaskOptions = { pattern: (raw) => (/^[A-Za-z]{3}[0-9][A-Za-z]/.test(raw) ? 'aaa9a99' : 'aaa-9*99'), case: 'upper' }; const taxId = ref('');const phone = ref('');const plate = ref('');const zip = ref('');</script> <template>    <StackPanel orientation="horizontal" spacing="0.75rem" align="start" wrap>        <StackPanel spacing="0.375rem" style="min-width: 16rem">            <Label for="it-zip">Postal code, a pattern</Label>            <InputText id="it-zip" v-model="zip" mask="99999-999" />            <small style="color: var(--vt-text-muted-color)">Value: {{ zip || '—' }}</small>        </StackPanel>        <StackPanel spacing="0.375rem" style="min-width: 16rem">            <Label for="it-phone">Phone, a list</Label>            <InputText id="it-phone" v-model="phone" :mask="['(99) 9999-9999', '(99) 99999-9999']" autocomplete="tel-national" />            <small style="color: var(--vt-text-muted-color)">Value: {{ phone || '—' }}</small>        </StackPanel>        <StackPanel spacing="0.375rem" style="min-width: 16rem">            <Label for="it-taxid">CPF or CNPJ, with the clear button</Label>            <InputText id="it-taxid" v-model="taxId" :mask="['999.999.999-99', '99.999.999/9999-99']" unmask clearable>                <template #prefix><Icon icon="user" /></template>            </InputText>            <small style="color: var(--vt-text-muted-color)">Value: {{ taxId || '—' }}</small>        </StackPanel>        <StackPanel spacing="0.375rem" style="min-width: 16rem">            <Label for="it-plate">Vehicle plate, an object</Label>            <InputText id="it-plate" v-model="plate" :mask="plateMask" />            <small style="color: var(--vt-text-muted-color)">Value: {{ plate || '—' }}</small>        </StackPanel>    </StackPanel></template>

Sizes, variants and states

<script setup lang="ts">import { InputText } from '@vitral/vue';</script> <template>    <InputText placeholder="Small" size="small" aria-label="Small" />    <InputText placeholder="Normal" aria-label="Normal" />    <InputText placeholder="Large" size="large" aria-label="Large" />    <InputText placeholder="Filled" variant="filled" aria-label="Filled" />    <InputText placeholder="Invalid" invalid aria-label="Invalid" />    <InputText placeholder="Disabled" disabled aria-label="Disabled" />    <InputText model-value="Read only" readonly aria-label="Read only" /></template>

Fluid

<script setup lang="ts">import { InputText } from '@vitral/vue';</script> <template>    <InputText placeholder="Fills its container" fluid aria-label="Fluid" /></template>

API

Read from packages/vue/src/components/InputText/types.ts, so it says what the component actually accepts.

Props

NameTypeDescription
size Size—
variant InputVariantDefaults to the plugin's `inputVariant`.
invalid boolean—
disabled boolean—
readonly boolean—
fluid boolean—
clearable booleanShows a clear button while there is text.
type string—
mask MaskPropThe 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 stringWhat an empty slot shows: one character, or a string as long as the mask (`'mm/dd/yyyy'`). Defaults to `_`.
autoClear booleanClear an unfinished value when the box loses focus. Defaults to true.
unmask booleanv-model receives only the typed characters, without the literals.
definitions MaskDefinitionsExtra slot characters, each with the characters it accepts.

Plus pt, dt and unstyled from BaseProps, see pass-through and unstyled mode.

Emits

EventPayloadDescription
clear ——
complete event: { originalEvent: Event; value: string }With a `mask`: every required slot is filled.

Slots

NameSlot propsDescription
prefix —Content inside the field, before the text: an icon, a currency sign.
suffix —Content inside the field, after the text: a unit, a button.