Socket
Socket
Sign inDemoInstall

react-otp-field

Package Overview
Dependencies
1
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-otp-field

Customizable OTP Field component for the web built with React.js


Version published
Weekly downloads
375
increased by27.55%
Maintainers
1
Install size
35.5 kB
Created
Weekly downloads
 

Readme

Source

react-otp-field

npm version npm npm

Customizable OTP Field component for the web built with React.js

Live Demo

Installation

npm install --save react-otp-field

Basic usage

import React, { useState } from 'react';
import OtpField from 'react-otp-field';

const App = () => {
    const [value, setValue] = useState('');

    return (
        <OtpField
            value={value}
            onChange={setValue}
            numInputs={6}
            onChangeRegex={/^([0-9]{0,})$/}
            autoFocus
            separator={<span>-</span>}
            isTypeNumber
            inputProps={{ className: 'otp-field__input', disabled: false }}
        />
    );
};

API

NameTypeRequiredDefault valueDescription
valueStringtrue''The value of the OTP Field.
onChangeFunctiontrueconsole.logReturns OTP values typed in inputs.
numInputsNumberfalse4Number of inputs.
onChangeRegexRegExfalsenoneRegEx for single onChange.
labelTextStringfalse'Enter verification code'Aria-label attribute for inputs.
classNamesStringfalse'otp-field'Class names for OTP Field component.
autoCompleteStringfalse'off'AutoComplete props for first input.
autoFocusBooleanfalsefalseAutoFocus on first input.
separatorComponentfalsenoneSeparator between inputs.
isTypeNumberBooleanfalsefalseType number for inputs.
hasErrorBooleanfalsefalseError class 'otp-field--has-error' for otp-field component.
inputPropsObjectfalsenoneProps for inputs.

Development

Run the development server:
npm run dev

Keywords

FAQs

Last updated on 18 Nov 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