Documentation
Form Components
OTP Input

OTPInput

The OTPInput component is designed for secure and user-friendly input of One-Time Passwords (OTPs). It features multiple input fields to capture each digit of the OTP individually, providing a clear and intuitive interface for users.

Installation

Install the package

npm i @start-base/react-form-elements

Add the styles

To use the React form elements styles in a Next.js project, import the styles in your layout.tsx file.

app/layout.tsx
import "@start-base/react-form-elements/styles.css";

Import the component

import OTPInput from '@start-base/react-form-elements/OTPInput';

Usages

OTP Input With Label

OTP Input With Length

OTP Input With Format

-
-

OTP Input With Separator

/

OTP Input With Timer

-
02:00

OTP Input With On Complete

-
02:00

OTP Input With On Resend

02:00

OTP Input Disabled

OTP Input Error Message

Error Message

OTP Input Error

API

This component is a wrapper around input-otp (opens in a new tab) component. All props from input-otp API Reference (opens in a new tab) can be passed to this component.

NameTypeDefaultDescription
namestringName of the input
labelstringnullLabel of the input
placeholderstringnullPlaceholder of the input
disableShrinkbooleanfalsePosition the label outside of the input
onChangefunctionCallback function that is fired when the value changes.
inputClassNamestringnullClassname for input element
labelClassNamestringnullClassname for label element
errorClassNamestringnullClassname for error element
disabledbooleanfalseDisable the input
errorstring or boolean or objectnullError message to display below the input. if value is a boolean input border will be change. Also you can pass schema validator error objects.
valuestringValue of the input
lengthobjectLength of the code.
timernumbernullOTP code timer limit of seconds.
onCompletefunctionCallback function that is fired when the all values entered.
onResendfunctionCallback function that is fired when the time out and cliced resend button.
formatarraynullInputs Separation array.
separatorstring"-"Separator element between inputs
resendLabelstring"Resend"Resend button text.

Styling