How to Configure Mobile Keyboard Input Mode for OTP Fields in Vue 3

The vue3-otp-input component exposes an inputmode prop that forwards the HTML inputmode attribute to each underlying <input> element, controlling whether mobile browsers display numeric, telephone, or text keyboards.

When building OTP (One-Time Password) verification flows in Vue 3, optimizing the mobile user experience requires configuring the appropriate virtual keyboard. The ejirocodes/vue3-otp-input library provides granular control over mobile keyboard input modes through a dedicated prop that maps directly to the HTML specification. Understanding how to leverage this property ensures users see the correct keypad layout—whether entering numeric codes, phone numbers, or alphanumeric tokens.

How the inputmode Prop Works in vue3-otp-input

The component architecture separates concerns between a wrapper component and individual input handlers. In src/components/single-otp-input.vue, the inputmode prop is declared with a default value of "numeric" (lines 7‑15) and bound directly to the native <input> element via :inputmode="inputmode" (lines 45‑46).

However, the main wrapper component in src/components/vue3-otp-input.vue redeclares this prop with a default value of "text" (lines 18‑27). This means developers must explicitly override the prop when instantiating the component to achieve numeric keyboard behavior, as the wrapper's default takes precedence in the final render.

Configuring Mobile Keyboard Modes for OTP Entry

Numeric Keypad (Default for Single Inputs)

To display a numeric keyboard optimized for OTP codes, explicitly set inputmode="numeric":

<template>
  <Vue3OtpInput
    v-model="otpCode"
    :numInputs="6"
    inputmode="numeric"
  />
</template>

<script setup lang="ts">
import { ref } from 'vue';
import Vue3OtpInput from 'vue3-otp-input';

const otpCode = ref('');
</script>

Telephone Keypad

For OTP scenarios involving phone number verification, use inputmode="tel" to trigger the telephone-specific keypad layout:

<Vue3OtpInput
  v-model="otpCode"
  :numInputs="4"
  inputmode="tel"
/>

Alphanumeric Input

When your OTP format includes letters and numbers, configure inputmode="text" combined with the appropriate inputType:

<Vue3OtpInput
  v-model="otpCode"
  :numInputs="5"
  inputmode="text"
  inputType="letter-numeric"
/>

Source Code Reference

The keyboard mode functionality is implemented across two core components:

  • src/components/single-otp-input.vue: Defines the inputmode prop with validation for HTML inputmode values and binds it to the native input element (lines 7‑15, 45‑46).
  • src/components/vue3-otp-input.vue: Acts as the public API, re-exporting the inputmode prop with a default value of "text" and forwarding it to each SingleOtpInput instance (lines 18‑27, 36‑37).

Summary

  • The inputmode prop in vue3-otp-input controls which virtual keyboard appears on mobile devices by forwarding the HTML inputmode attribute to each OTP digit field.
  • Set inputmode="numeric" to display numeric keypads for standard OTP codes, overriding the wrapper component's default "text" value.
  • Alternative modes include "tel" for telephone-style keypads and "text" for alphanumeric OTP entry.
  • The implementation spans src/components/single-otp-input.vue (input binding) and src/components/vue3-otp-input.vue (prop forwarding).

Frequently Asked Questions

What is the default inputmode in vue3-otp-input?

The wrapper component (src/components/vue3-otp-input.vue) defaults to "text", while the underlying single input component defaults to "numeric". Because the wrapper passes its prop value down, you must explicitly set inputmode="numeric" on the component instance to trigger numeric keyboards.

Why does my OTP field show an alphabetic keyboard instead of numeric?

This occurs because the main Vue3OtpInput component initializes the inputmode prop with a default value of "text". Without explicit override, the wrapper forwards "text" to all child inputs, causing mobile browsers to display the standard text keyboard rather than the numeric pad.

Can I use inputmode='tel' for OTP verification codes?

Yes. Setting inputmode="tel" is appropriate when the OTP is sent to a phone number or when you prefer the telephone keypad layout, which typically features larger touch targets and a distinct visual style optimized for numeric entry on mobile devices.

How do I enable alphanumeric OTP entry in vue3-otp-input?

To accept both letters and numbers, set inputmode="text" combined with inputType="letter-numeric". This configuration displays the standard text keyboard while allowing alphanumeric characters in the OTP fields.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →