Package Exports
- react18-input-otp
- react18-input-otp/lib/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react18-input-otp) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
react18-input-otp
A fully customizable, one-time password (OTP) and phone number with separator input component for the web built with React.

Installation
To install the latest stable version:
npm install --save react18-input-otpBasic 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 |
Type | Required | Default | Description |
|---|---|---|---|---|
| numInputs | number | true | 4 | Number of OTP inputs to be rendered. |
| onChange | function | true | console.log | Returns OTP code typed in inputs. |
| 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. |
| separator | component |
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. |
| focusStyle | style (object) / className (string) | false | none | Style applied or class passed to inputs on focus. |
| isDisabled | boolean | false | false | Disables all the inputs. |
| disabledStyle | style (object) / className (string) | false | none | Style applied or class passed to each input when disabled. |
| hasErrored | boolean | false | false | Indicates there is an error in the inputs. |
| errorStyle | style (object) / className (string) | false | none | Style applied or class passed to each input when errored. |
| shouldAutoFocus | boolean | false | false | Auto focuses input on initial page load. |
| isInputNum | boolean | false | false | Restrict input to only numbers. |
| isInputSecure | boolean | false | false | Masks input characters. |
| data-cy | string | false | - | Test attribute passed to the inputs. |
| data-testid | string | false | - | Test attribute passed to the inputs. |
Development
To run the development server:
npm run devChecklist
- Add flowtypes
- Add ESLint, Prettier for code quality
- Add styling support for states including focus/disabled
- Write tests
Contributing
Feel free to open issues and pull requests!
License
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!
