New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react18-input-otp

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react18-input-otp

A fully customizable, one-time password (OTP) and phone number with separator input component for the web built with React.

latest
Source
npmnpm
Version
1.1.4
Version published
Weekly downloads
20K
1.24%
Maintainers
1
Weekly downloads
 
Created
Source

react18-input-otp

npm version npm npm

A fully customizable, one-time password (OTP) and phone number with separator input component for the web built with React. Tested on Web, Android, and iOS. This package supports all react versions.

see here

Live Demo

CodeSandbox

Features

  • A fully customisable OTP input package with support of React 18 and Typescript.
  • It works great on both react and ionic app. Works like a charm on mobile too.
  • You can specify only numeric inputs with inputNum prop.
  • Works perfectly with clipboard paste feature on web and mobile.
  • The only OTP input package on npm that supports 'enter' key to submit.
  • Zero OTP paste issues on Android.
  • Easy paste on iOS chrome, read from SMS feature.
  • Supports onSubmit optional prop. You do not even need a button to submit.
  • You can use this package for phone number inputs too.
  • You can use this package for passcode fields too with inputSecure prop.
  • You can provide custom css as well as input props to the React18-input-otp.
  • 0 dependencies.
  • Minzipped size only 3.6 kb.
  • No open issues.
  • No security bugs.

Installation

NPM

To install the latest stable version:

npm install --save react18-input-otp

Basic usage:

As class component
import React, { Component } from 'react';
import OtpInput from 'react18-input-otp';

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>} />;
  }
}
As functional component with hooks
import React, { useState } from 'react';
import OtpInput from 'react18-input-otp';
export default function ReactOtpInput() {
  const [otp, setOtp] = useState('');
  const handleChange = (enteredOtp) => {
    setOtp(enteredOtp);
  };
  return <OtpInput value={otp} onChange={handleChange} numInputs={6} separator={<span>-</span>} />;
}

API

Name
TypeRequiredDefaultDescription
idstringfalsenoneProvide unique id for your OTP input.
numInputsnumbertrue4Number of OTP inputs to be rendered.
onChangefunctiontrueconsole.logReturns OTP code typed in inputs.
onSubmitfunctionfalseconsole.logReturns OTP code on submit. This allows to submit the OTP on enter key too.
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.
separateAfternumber
false1Provide the count to set the separater after every input. For instance, 3 would add - after every third input.
autoCompletestring
falseoffProvide the autocomplete feature for the input. Now, supports one-time-code as autoComplete.
ariaLabelOverridestring
falsenoneProvide the custom arialabel for the 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.
isSuccessedbooleanfalsefalseIndicates there is success with the inputs..
successStylestyle (object) / className (string)falsenoneStyle applied or class passed to each input when success.
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.
custom-test-idstringfalse-Custom test attribute passed to the inputs.
custom-test-attrstringfalse-Custom test attribute passed to the inputs.
inputPropsInputHTMLAttributes | InputHTMLAttributes[]false-Custom input props.

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

Special Thanks to devfolioco. This project is build on top of react-otp-input.

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

Keywords

otp

FAQs

Package last updated on 10 Jul 2023

Did you know?

Socket

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