Socket
Socket
Sign inDemoInstall

@unit-finance/react-otp-input

Package Overview
Dependencies
5
Maintainers
3
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @unit-finance/react-otp-input

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


Version published
Weekly downloads
407
increased by140.83%
Maintainers
3
Install size
30.4 kB
Created
Weekly downloads
 

Readme

Source

react-otp-input

npm version npm npm All Contributors

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

see here

Live Demo

CodeSandbox

Installation

NPM

To install the latest stable version:
npm install --save react-otp-input
Basic usage:
import React, { Component } from 'react';
import OtpInput from 'react-otp-input';

export default class App extends Component {
  state = { otp: '' };

  handleChange = (otp) => this.setState({ otp });

  render() {
    return (
      <OtpInput
        value={this.state.otp}
        onChange={this.handleChange}
        numInputs={6}
        separator={<span>-</span>}
      />
    );
  }
}

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 to numInputs.
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.

Breaking changes when porting to v1.0.0

react-otp-input is now a controlled component to facilitate functionalities that weren't possible before from the application using it, such as clearing or pre-assigning values. For v1.0.0 and above, a value prop needs to be passed in the component for it to function as expected.

Development

To run the development server:
npm run dev

Checklist

PRs Welcome Open Source Love

  • Add flowtypes
  • Add ESLint, Prettier for code quality
  • Add styling support for states including focus/disabled
  • Write tests

Contributing

GitHub issues GitHub pull requests

Feel free to open issues and pull requests!

License

NPM

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Abhishek Warokar

💻 🎨 🚧 🤔 👀

Aj

💻 🎨 🤔

Aromal Anil

💻 🔧

Gabriele Corti

💻 ️️️️♿️

Anoop

💻

Dewansh Rawat

🐛

Ishan Chhabra

💻

yaojie

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

Keywords

FAQs

Last updated on 18 Dec 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc