react-individual-character-input-boxes
TypeScript icon, indicating that this package has built-in type declarations

1.2.1 • Public • Published

react-individual-character-input-boxes

npm version Join the chat at https://gitter.im/single-character-input-boxes/Lobby

React Individual Character Input Boxes (RICIBs) are individual inputs that are separate from each other but functionally act similar as a regular input box. Motivation came from Apples similar input boxes used for their two-factor authorization: apple input boxes

Demo

You can view a demo of this component here!

Installation

$ npm i --save react-individual-character-input-boxes

How To Use

Import:

import RICIBs from 'react-individual-character-input-boxes';

Example code:

handleOutput (string) {
    // Do something with the string
  }

  render () {
    return (
      <div>
        <RICIBs
          amount={5}
          autoFocus
          handleOutputString={this.handleOutput}
          inputProps={[
            { className: "first-box" },
            { style: { "color": "orange" } },
            { placeholder: "_" }
          ]}
          inputRegExp={/^[0-9]$/}
        />
      </div>
    )
  }

Props:

Prop Type Required Description
amount Number sets the number of input boxes. (default is 5)
autoFocus Boolean When true, the first input box will automatically be selected on page load. (default false)
handleOutputString Function Implement it to handle the string output of the module.
inputProps Object or Array<Object> Allows you to pass through properties to the input boxes. With this you can customize attributes (including styles) for all of the boxes by using an Object. To customize each box individually use an array of objects where each item in the array represents a box.
inputRegExp RegExp Tells the component which characters to allow as inputs. (default is /^[0-9]$/ which is only numbers)
password Boolean Masks in the input if set as true (default is false)

Help, I cant get it to work or I want a feature!

Please feel free to submit an issue if you are running into trouble or have an idea for additional functionality!

BUG

I am aware that there is a bug (mostly seems to occur in Chrome) where if you type to quickly sometimes the selection will spazz out and jump between inputs. I think it is a browser bug, but if anybody has any idea how to possibly fix this let me know please!

License

MIT © Danny Radden

Package Sidebar

Install

npm i react-individual-character-input-boxes

Weekly Downloads

607

Version

1.2.1

License

MIT

Unpacked Size

27 kB

Total Files

6

Last publish

Collaborators

  • dradden