Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

✔️ OTP Input Component for React

License

NotificationsYou must be signed in to change notification settings

hunghg255/reactjs-otp-input

 
 

Repository files navigation

logo

A library reactjs to create OTP input

NPM VersionNPM DownloadsMinizipContributorsLicense

A fully customizable, one-time password input component for the web built with React.

see here

Support auto fill on mobile (safari, chrome....)

see here

Live Demo

Installation

NPM

To install the latest stable version:

pnpm install reactjs-otp-input@latest

Basic usage:

importReact,{Component}from'react';import{OtpInput}from'reactjs-otp-input';constApp=()=>{const[otp,setOtp]=useState('');consthandleChange=(otp)=>setOtp(otp);return<OtpInputvalue={otp}onChange={handleChange}numInputs={6}separator={<span>-</span>}/>;};

To run the development server:

npm run dev

API

Name
TypeRequiredDefaultDescription
numInputsnumbertrue4Number of OTP inputs to be rendered.
onChangefunctiontrueconsole.logReturns OTP code typed in inputs.
valuestring / numbertrue''The value of the OTP passed into the component.
placeholderstringfalsenoneSpecify an expected value of each input. The length of this string should be equal tonumInputs.
separatorcomponent
falsenoneProvide a custom separator between inputs by passing a component. For instance,<span>-</span> would add- between each input.
containerStylestyle (object) / className (string)falsenoneStyle applied or class passed to container of inputs.
inputStylestyle (object) / className (string)falsenoneStyle applied or class passed to each input.
focusStylestyle (object) / className (string)falsenoneStyle applied or class passed to inputs on focus.
isDisabledbooleanfalsefalseDisables all the inputs.
disabledStylestyle (object) / className (string)falsenoneStyle applied or class passed to each input when disabled.
hasErroredbooleanfalsefalseIndicates there is an error in the inputs.
errorStylestyle (object) / className (string)falsenoneStyle applied or class passed to each input when errored.
shouldAutoFocusbooleanfalsefalseAuto focuses input on initial page load.
isInputNumbooleanfalsefalseRestrict input to only numbers.
isInputSecurebooleanfalsefalseMasks input characters.
data-cystringfalse-Test attribute passed to the inputs.
data-testidstringfalse-Test attribute passed to the inputs.

About

Buy Me A Coffee

Gia Hung –hung.hg


[8]ページ先頭

©2009-2025 Movatter.jp