PinInput
Included in RC.12
Available in Mavis 0.1.0-rc.12 for Vue + Vite, Nuxt and NativeScript. Keep the Mavis packages at the same version.
<MPinInput
v-model="code"
label="Verification code"
:length="6"
autocomplete="one-time-code"
@complete="checkCode"
/>| Prop | Type | Default | Contract |
|---|---|---|---|
modelValue / label | string | empty / required | Canonical numeric code and accessible editor name. |
length | number | 6 | Integer between 2 and 12. |
disabled / readonly / required | boolean | false | Input availability and Web form validation. |
id / name / form | string | — | Editor id and Web form association. |
error / helperText | string | — | Associated validation/help message. |
One real editor beneath decorative cells preserves selection, paste and autofill. Numeric strings retain leading zeros; full-width digits and pasted separators are normalized. complete(value) fires after a user edit fills the code, not after a programmatic model update. It does not verify the code or perform authentication. Native autofill availability depends on the operating system and application setup. Web uses one-time-code, a single named form field and native pattern validation; focus()/blur() target that editor.
<script setup lang="ts">
import { computed, ref } from 'vue'
import { useCatalogLocale } from '../locale'
const props = defineProps<{ lang?: 'en' | 'pt' }>()
const { locale } = useCatalogLocale(() => props.lang)
const pt = computed(() => (props.lang ?? locale.value) === 'pt')
const t = (en: string, br: string) => (pt.value ? br : en)
function clearCode() {
code.value = ''
complete.value = ''
}
const code = ref(''),
complete = ref(''),
error = ref(false),
disabled = ref(false)
</script>
<template>
<MColumn gap="lg">
<MText text="ONE LAST STEP" variant="overline" tone="primary" />
<MText :text="t('Welcome back.', 'Bom ter você de volta.')" variant="title" />
<MText
:text="
t(
'Enter the six-digit code sent to your email.',
'Digite o código de seis dígitos enviado ao seu e-mail.',
)
"
tone="muted"
/>
<MPinInput
v-model="code"
:label="t('Verification code', 'Código de verificação')"
:disabled="disabled"
:error="
error
? t('This code has expired. Request another.', 'O código expirou. Solicite outro.')
: undefined
"
:helperText="t('You can paste the entire code.', 'Você pode colar o código inteiro.')"
@complete="(value) => (complete = value)"
/>
<MRow gap="sm" wrap
><MButton
:text="t('Try a pasted code', 'Testar um código')"
variant="secondary"
:disabled="disabled"
@click="code = '012345'" /><MButton
:text="t('Clear', 'Limpar')"
variant="ghost"
@click="clearCode"
/></MRow>
<MRow gap="sm" wrap
><MSwitch v-model="error" :label="t('Show error', 'Mostrar erro')" /><MSwitch
v-model="disabled"
:label="t('Disable input', 'Desabilitar campo')"
/></MRow>
<MText id="pin-complete" :text="complete || '—'" variant="caption" tone="muted" />
</MColumn>
</template>Motion
Each digit pops into its cell as it arrives, and a completed code is greeted by a short wave that runs across the cells in order. A pasted code skips the individual pops and only plays the wave. When an error appears, the row of cells shakes once. The cells are decorative: the real editor lying over them never moves, so typing, selection and autofill are not disturbed. Under reduced motion nothing moves; a new digit only fades in.
Desktop
On the desktop each digit is an editor of its own: typing moves to the next one, Backspace in an empty one goes back, the arrow keys move between digits and a pasted code fills them from where it lands. Digits after the first empty one wait until it is filled, and name and form have no effect outside the browser; see Desktop components.