react-otp-field
Advanced tools
Weekly downloads
Changelog
v3.0.1
Fixed dependencies
Readme
Customizable OTP Field component for the web built with React.js
npm install --save react-otp-field
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 }}
/>
);
};
Name | Type | Required | Default value | Description |
---|---|---|---|---|
value | String | true | '' | The value of the OTP Field. |
onChange | Function | true | console.log | Returns OTP values typed in inputs. |
numInputs | Number | false | 4 | Number of inputs. |
onChangeRegex | RegEx | false | none | RegEx for single onChange. |
labelText | String | false | 'Enter verification code' | Aria-label attribute for inputs. |
classNames | String | false | 'otp-field' | Class names for OTP Field component. |
autoComplete | String | false | 'off' | AutoComplete props for first input. |
autoFocus | Boolean | false | false | AutoFocus on first input. |
separator | Component | false | none | Separator between inputs. |
isTypeNumber | Boolean | false | false | Type number for inputs. |
hasError | Boolean | false | false | Error class 'otp-field--has-error' for otp-field component. |
inputProps | Object | false | none | Props for inputs. |
npm run dev
FAQs
Customizable OTP Field component for the web built with React.js
The npm package react-otp-field receives a total of 604 weekly downloads. As such, react-otp-field popularity was classified as not popular.
We found that react-otp-field demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.