3.1.1 • Published 5 months ago

react-otp-input v3.1.1

Weekly downloads
18,878
License
MIT
Repository
github
Last release
5 months ago

react-otp-input

npm version npm npm All Contributors

A fully customizable, one-time password input component for the web built with React.

see here

Live Demo

Installation

NPM

To install the latest stable version:

npm install --save react-otp-input

Still using v2?

No problem! You can find the documentation for v2 here

Basic usage:

import React, { useState } from 'react';
import OtpInput from 'react-otp-input';

export default function App() {
  const [otp, setOtp] = useState('');

  return (
    <OtpInput
      value={otp}
      onChange={setOtp}
      numInputs={4}
      renderSeparator={<span>-</span>}
      renderInput={(props) => <input {...props} />}
    />
  );
}

API

⚠️ Warning

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

Migrating from v2

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.

Migrating from v1

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.

Development

To run the vite example:

cd example
npm run dev

Checklist

PRs Welcome Open Source Love

  • Write tests
  • Add actions for lint checks and tests

Contributing

GitHub issues GitHub pull requests

Feel free to open issues and pull requests!

License

NPM

Contributors ✨

Thanks goes to these wonderful people (emoji key):

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

@pubngo-stack/account-api-browser@borderfreefinancial/revo-core@borderfreefinancial/revo-core-api@opium-react/otp-input@infinitebrahmanuniverse/nolb-react-oboompay-react-sdk@everything-registry/sub-chunk-2601@wad-labs/ui-kitfuse-cognito-logingoku_00_package1fp-widgetsguardianscriptexchange-sharedewz-ui-teste-brokerfccs-sdkfindingpi-react-componentssixsprints-react-uilime-react-schemalogin-grandautomationstorefront-sdk@limegroup/lime-react-schema@magicboxcd/ui@purposeinplay/core-v2@questlabs/react-sdk@oystrfinance/direct-debit-client@myestery/oystr-onboarding@meliplatform/web-core@nikamanish/dukaan-theme-contexts@stokr/components-library@tap-payments/auth-jsconnect@smarteye/opticavan-beatboilerplate223bornfight-core-componentsbrass-ui-kit@withlanda/humphrey@verysell-group/verypay-sdkbcs-uibank-components-originalcaptcha-component-reactccw-frontend-componentcakemail-ui-components-v2citydi-bpms-sdkcompany-moduleclient-verification-trential-next-sdkclient-verification-trential-next-sdk-testclient-verification-trential-sdkclient-verification-trential-sdk-testclient-verification-trential-test-sdkclinic-designloanfront-booster-s5loanfront-ui-componentsloanfront-ui-testingjumbo-reactkrl-alfredsummit-registration-litemsys-dsticketmelon-webmicro_front_end_nagarrotccm-packagetelemdnow-patient-frontend-v2mpc-sdk-react-devtest-iki-mini-appmergestor-ui-componentstest-otp-inputonsu-login-pageopendesktopappordering-ui-externalordering-uiordering-ui-admin-externalzs-loginmedvatic-pluginnc-contracts-modulemuthaka-next-starternebuia-react-componentnebuia-react-component-v2@accelbyte/widgets@accelbyte/widgets-v2react-codebase@akinon/pz-otp@citizendev/bubble-otp-input@aooth/aooth-react-sdk@aooth/react@citizendev/bubble-file-uploader@comparaonline/comparanent-uirenos-uirenos-ui-temp-miftarenos-ui-temp1@froogal.ai/loyalty-sdk-js@giveindia/loginmodule@afriswap/rate-converterpsplink-metadata@foundbyte/ui@jitera/jitera-web-ui-library@camped-ui/input-otp@iotbiz/reactrisingstar_newlaunchpad_microfrontend@itcase/ui@goku_vegeta/package1
3.1.1

5 months ago

3.1.0

7 months ago

3.0.4

10 months ago

3.0.3

10 months ago

3.0.2

1 year ago

3.0.1

1 year ago

3.0.0

1 year ago

3.0.0-alpha-2

1 year ago

3.0.0-alpha-1

1 year ago

3.0.0-alpha-3

1 year ago

2.4.0

3 years ago

2.3.1

3 years ago

2.3.0

4 years ago

2.3.0-next.1

4 years ago

2.3.0-next.2

4 years ago

2.3.0-next.0

4 years ago

2.2.0

4 years ago

2.1.0

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.2

5 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago