Movatterモバイル変換


[0]ホーム

URL:


⚠️

Security Update: npm classic token creation is now disabled. Existing classic tokens will be revoked onNovember 19, 2025. Migrate to trusted publishing or granular access tokens to avoid disruption.Learn more.

reactjs-otp-input
TypeScript icon, indicating that this package has built-in type declarations

2.0.10 • Public • Published

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

Package Sidebar

Install

npm i reactjs-otp-input

Weekly Downloads

4,352

Version

2.0.10

License

ISC

Unpacked Size

77.2 kB

Total Files

10

Last publish

Collaborators

  • hunghg255

[8]ページ先頭

©2009-2025 Movatter.jp