Gathering detailed insights and metrics for react-otp-input
Gathering detailed insights and metrics for react-otp-input
Gathering detailed insights and metrics for react-otp-input
Gathering detailed insights and metrics for react-otp-input
npm install react-otp-input
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
667 Stars
217 Commits
430 Forks
10 Watching
5 Branches
45 Contributors
Updated on 23 Nov 2024
Minified
Minified + Gzipped
TypeScript (75.88%)
CSS (19.19%)
HTML (2.72%)
JavaScript (2.2%)
Cumulative downloads
Total Downloads
Last day
0.4%
34,033
Compared to previous day
Last week
4.9%
181,141
Compared to previous week
Last month
2.8%
741,837
Compared to previous month
Last year
66.5%
7,741,704
Compared to previous year
20
A fully customizable, one-time password input component for the web built with React.
npm install --save react-otp-input
No problem! You can find the documentation for v2 here
1import React, { useState } from 'react'; 2import OtpInput from 'react-otp-input'; 3 4export default function App() { 5 const [otp, setOtp] = useState(''); 6 7 return ( 8 <OtpInput 9 value={otp} 10 onChange={setOtp} 11 numInputs={4} 12 renderSeparator={<span>-</span>} 13 renderInput={(props) => <input {...props} />} 14 /> 15 ); 16}
Name | Type | Required | Default | Description |
---|---|---|---|---|
numInputs | number | true | 4 | Number of OTP inputs to be rendered. |
renderInput | function | true | none | A function that returns the input that is supposed to be rendered for each of the input fields.
The function will get two arguments: inputProps and index . inputProps is an object that contains all the props that should be passed to the input being rendered (Overriding these props is not recommended because it might lead to some unexpected behaviour). index is the index of the input being rendered.
|
onChange | function | true | console.log | Returns OTP code typed in inputs. |
onPaste | function | false | none | Provide a custom onPaste event handler scoped to the OTP inputs container. Executes when content is pasted into any OTP field.
Example: const handlePaste: React.ClipboardEventHandler |
value | string / number | true | '' | The value of the OTP passed into the component. |
placeholder | string | false | none | Specify an expected value of each input. The length of this string should be equal to numInputs . |
renderSeparator | component / function | false | none | Provide a custom separator between inputs by passing a component. For instance, <span>-</span> would add - between each input. |
containerStyle | style (object) / className (string) | false | none | Style applied or class passed to container of inputs. |
inputStyle | style (object) / className (string) | false | none | Style applied or class passed to each input. |
inputType | <input> type | false | text | The type of the input that will be passed to the input element being rendered. In v2 isInputNum used to set the input type as tel and prevented non numerical entries, so as to avoid the spin buttons added to the inputs with input type number . That behaviour is still supported if you pass tel to the inputType prop. |
shouldAutoFocus | boolean | false | false | Auto focuses input on initial page load. |
skipDefaultStyles | boolean | false | false | The component comes with default styles for legacy reasons. Pass true to skip those styles. This prop will be removed in the next major release. |
Do not override the following props on the input component that you return from the renderInput
prop. Doing so might lead to unexpected behaviour.
ref
value
onChange
onFocus
onBlur
onKeyDown
onPaste
onInput
type
inputMode
The v3 of react-otp-input
is a complete rewrite of the library. Apart from making the API more customizable and flexible, this version is a complete rewrite of the library using TypeScript and React Hooks. Here are the breaking changes that you need to be aware of:
You now need to pass your own custom input component that will be rendered for each of the input fields via renderInput
prop. This gives you the flexibility to customize the input fields as you desire. This also means that props like focusStyle
, isDisabled
, disabledStyle
, hasErrored
, errorStyle
, isInputNum
, isInputSecure
, data-cy
and data-testid
are no longer supported. You can achieve the same functionality and more by passing the relevant props directly to the input component that you return from the renderInput
prop.
The separator
prop has now been renamed to renderSeparator
. This prop now apart from accepting a component that will be rendered as a separator between inputs like it used to, now also accepts a function that returns a component. The function will get the index of the separator being rendered as an argument.
A new prop called inputType
has been added to the component. This prop can be used to specify the type of the input that will be passed to the input element being rendered. The default value of this prop is number
.
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.
cd example
npm run dev
Feel free to open issues and pull requests!
Thanks goes to these wonderful people (emoji key):
Abhishek Warokar 💻 🎨 🚧 🤔 👀 | Aj 💻 🎨 🤔 | Aromal Anil 💻 🔧 | Gabriele Corti 💻 ️️️️♿️ | Anoop 💻 | Dewansh Rawat 🐛 | Ishan Chhabra 💻 |
yaojie 💻 | Prateek Surana 💻 🚧 🤔 📖 🎨 | Süleyman Barış Eser 🐛 | Steve Domino 💻 | Stephen Hogan 💻 |
This project follows the all-contributors specification. Contributions of any kind welcome!
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 5/16 approved changesets -- score normalized to 3
Reason
SAST tool is not run on all commits -- score normalized to 1
Details
Reason
9 existing vulnerabilities detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More