Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@healerlab/vue3-simple-otp-input

healerlab572MIT0.0.9TypeScript support: included

Powerful, lightweight, and reusable OTP input component for Vue 3

vue, vue3, component, library, otp input, pincode, otp, input, otp input, vue otp input, vue 3 otp input, one-time password, one time password, payment password, vue composition API, one time password input, one time password input component, one time password input component built with vue, one time password input component built with vue 3, vue split input

readme

Vue 3 simple OTP input

npm npm GitHub

Demo

Demo and docs

Installation

Prerequisites

To get started, you can install vue3-simple-otp-input with:

npm i @healerlab/vue3-simple-otp-input

with pnpm:

pnpm add @healerlab/vue3-simple-otp-input

with yarn:

yarn add @healerlab/vue3-simple-otp-input

Usage

Import the component and register it locally in your Vue component:

<script setup lang="ts">
import { HOtpInput } from "@healerlab/vue3-simple-otp-input";

const handleFinish = (otpCode: string) => {
  // write logic with received code
}

const handleChange = (otpCode: string) => {
  // write logic with changed code
}

const getCodeWithSeparator = () => {
  // get code with separator
  // otpInput?.value?.genResultWithSeparator()
}
</script>

Use the component in your template:

<HOtpInput
  :length="6" 
  type="text" 
  @on-finish="handleFinish"
  @on-change="handleChange" 
  wrapperClassName="otp-input"
  :outlined="true"
  ref="otpInput"
  :only-number="true"
  separator="-" // separator support
  separatorType="middle" // middle or all
/>

This is minimal style for your input, you can change it to match your use-case:

<style scoped lang="scss">
.otp-input {
  :deep(input) {
    outline: none;
    width: 30px;
    padding: 12px;
    font-size: 22px;
    border: none;
    margin-left: 10px;
    text-align: center;
    &:first-child {
      margin-left: 0;
    }
    &:focus {
      outline: none
    }
  }

  :deep(span) {
    padding: 0 0px 0 10px;
    font-size: 30px;
  }
}
</style>

See the Vue3 Simple OTP Input page for more information.