1.3.1 • Published 1 year ago

react-pin-input v1.3.1

Weekly downloads
8,464
License
MIT
Repository
github
Last release
1 year ago

react-pin-input

There is another package for managing PIN input. Check and see which suits you better.

Build Status

React-PIN-Input is a React component o capture PIN/MPIN like input

alt tag

Demo

https://codesandbox.io/s/8jnlxw359

Installation

npm install react-pin-input --save

Usage

The component takes in the length of the PIN and two callback to notifiy change and completion. The index is the input which is currently in focus.

import PinInput from 'react-pin-input';

<PinInput 
  length={4} 
  initialValue=""
  secret
  secretDelay={100} 
  onChange={(value, index) => {}} 
  type="numeric" 
  inputMode="number"
  style={{padding: '10px'}}  
  inputStyle={{borderColor: 'red'}}
  inputFocusStyle={{borderColor: 'blue'}}
  onComplete={(value, index) => {}}
  autoSelect={true}
  regexCriteria={/^[ A-Za-z0-9_@./#&+-]*$/}
/>
AttributeTypeDescription
lengthnumberNumber of inputs
initialValuenumber|stringInitial value of inputs
typestringType of input allowed
if numeric, the input will take only numbers
if custom, the input will take other than numbers
secretbooleanIf you set the secret attibute, the input will be hidden as shown below.
secretDelaynumberIf you set the secret attibute, then you can optionally add secretDelay ms to hide the inputs as you type.
disabledbooleanIf you set the disable attibute, the input will be disabled.
focusbooleanSetting the focus attibute will set the default focus on the first input element.
onChangefunctionCallback function invoked on input change. The first parameter is the value and the second is the index of the input that is currently in focus
onCompletefunctionCallback function invoked when all inputs have valid values. The first parameter is the value and the second is the index of the input that is currently in focus
styleobjectStyle for the container div
inputStyleobjectStyle for the input element
inputFocusStyleobjectStyle for the input element when on focus
autoSelectbooleanSetting autoSelect to false will stop automatically highlighting input values on focus. This eliminates popup focus flashing on iOS.
regexCriteriaanyAdd validation for alphanumeric type. NOTE: default value is /^ A-Za-z0-9_@./#&+-*$/

Display when secret is set alt tag

Additional APIs

<PinInput length={4} ref={(n) => ele=n} />
  • ele.focus() to set focus on the first input element.
  • ele.clear to clear the values

Custom Style

You can update the style via following props

  • style
  • inputStyle
  • inputFocusStyle

Or another option is to override the default style(shown below is scss. For css refer ).

.pincode-input-container
{
  .pincode-input-text
  {
    padding:0 !important;
    margin:0 2px;
    text-align:center;
    border: 1px solid;
    background: transparent;
    width: 50px;
    height: 50px;
  }
  .pincode-input-text:focus
  {
    outline:none;
    box-shadow:none;
  }
}

For developers

New build

npm run build

Run dev server

npm run dev

Run test

npm run test

1.3.1

1 year ago

1.2.0

2 years ago

1.2.1

2 years ago

1.3.0

2 years ago

1.1.0

2 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.9.5

4 years ago

0.9.4

4 years ago

0.9.3

4 years ago

0.9.2

4 years ago

0.9.1

4 years ago

0.9.0

5 years ago

0.8.0

5 years ago

0.7.0

6 years ago

0.6.6

6 years ago

0.6.5

6 years ago

0.6.42

6 years ago

0.6.41

6 years ago

0.6.4

6 years ago

0.6.3

6 years ago

0.6.2

6 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.5.3

6 years ago

0.5.2

6 years ago

0.5.1

6 years ago

0.5.0

6 years ago

0.4.3

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.5

7 years ago

0.3.4

7 years ago

0.3.3

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.1.8

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago