Giter Club home page Giter Club logo

react-pin-input's Introduction

react-pin-input

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

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="numeric"
  style={{padding: '10px'}}  
  inputStyle={{borderColor: 'red'}}
  inputFocusStyle={{borderColor: 'blue'}}
  onComplete={(value, index) => {}}
  autoSelect={true}
  regexCriteria={/^[ A-Za-z0-9_@./#&+-]*$/}
/>
Attribute Type Description
length number Number of inputs
initialValue number|string Initial value of inputs
type string Type of input allowed
if numeric, the input will take only numbers
if custom, the input will take other than numbers
secret boolean If you set the secret attibute, the input will be hidden as shown below.
secretDelay number If you set the secret attibute, then you can optionally add secretDelay ms to hide the inputs as you type.
disabled boolean If you set the disable attibute, the input will be disabled.
focus boolean Setting the focus attibute will set the default focus on the first input element.
onChange function Callback 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
onComplete function Callback 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
style object Style for the container div
inputStyle object Style for the input element
inputFocusStyle object Style for the input element when on focus
autoSelect boolean Setting autoSelect to false will stop automatically highlighting input values on focus. This eliminates popup focus flashing on iOS.
regexCriteria any Add 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

Buy Me A Coffee

react-pin-input's People

Contributors

aabanaag avatar adheeshdh avatar armanio avatar arunghosh avatar arunghosh-kv avatar bogdanp05 avatar callumlocke avatar dependabot-preview[bot] avatar dependabot-support avatar fer0x avatar johnnyxbell avatar nombrekeff avatar paulreeve avatar quitrk avatar richardpeng avatar rvdkooy avatar sidmorad avatar sloba88 avatar xavierdefontaine avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-pin-input's Issues

Not all custom styles are applied

So, I've installed today this module in my React-JS project, and I'm confronting now with an issue. Not all the styles written in .pincode-input-text and .pincode-input-text:focus classes are applied. In rest, everything's working awesome...

Here's the code snippet of these 2 classes

.pincode-input-text {
    text-align: center;
    color: #fff;
    border-color: #f5f5f5;
    background-color: #070713;
    width: 50px;
    height: 50px;

    font-size: 1rem;
    font-family: 'Roboto', sans-serif;
    line-height: 1.5;
  }

  .pincode-input-text:focus {
    border-color: #fff;
    outline: none;
    box-shadow: none;
  }

And here's a screen from my inspection tool:

image

P.S. Yeah, I'm using SCSS, so I've done everything according to the pattern shown in Readme.md

Browser Support

I've been using this library in a project. I've been testing using Browserstack and I've run into issues on older browsers:

  • The focus doesn't jump to the next input automatically
  • onComplete never fires

I've seen this so far on:

  • iphone 6 running safari 8
  • windows 7 running IE 11
  • Nokia Lumia 930 running windows phone 8.1
  • HTC One M8 android 4.4

I'll dig into this further myself and report back. If you've got an ideas let me know!

Please add changelog

It is difficult to tell what changed from previous release.

I can see 0.8.0 was introduced with "fixed security issues" commit but I don't see what the issue was and if the release contains other changes besides bumping some dependencies.

No keypad showing in Android devices

nokeypad
Hi

I am not getting the keypad on the android devices if I set type="number". Please see image.

Cordova and ReactJS are used in this project that I am working on.

<PinInput
    length={4}
    secret
    type="numeric"
    ref={p => pin = p}
    onComplete={(value) => {
      props.onComplete(value)
      pin.clear()
    }}
  />

thx in advance

Expose events to API

It would be great to be able to have access to methods through the api. I'd like to implement a custom keyboard for this.

Placeholder for inputs

Hello devs!
I was wondering how to set placeholders for every input, as the param "placehoder" doesn't exist.
Actually, I managed to do this with javascript, but it's not the best solution cuz when you text inside the input and delete it, the placeholder isn't there anymore:

const [inputs, setInputs] = useState([]);

useEffect(() => {
    setInputs(document.getElementsByClassName('pincode-input-text'));
    for (let iinput = 0; input < inputs.length; input += 1) {
        inputs[i].setAttribute('placeholder', '•');
    }
}, [inputs]);

Any suggestions?

Issue understanding how to clear PinInput fields after invalid attempt

Using React with Next JS and everything with the component seems to be running smoothly after installation and API implementation. Now my only problem seems to be how to clear the fields. Not sure how in my React functional component to access the clear() function of the element. Any suggestions would be appreciated, thanks!

input type when use secret

PIN is secret and only number

<PinInput length={6} focus // secret inputStyle={{ borderColor: '#5e07a0', borderRadius: '50%', width: '43px', maxwidth: '15%' }} inputMode="tel" pattern="[0-9]*" type="tel" onChange={onChange} />

but when i use secret it show another type in android phone

Screen Shot 2021-01-20 at 16 50 45

but when not using secret

Screen Shot 2021-01-20 at 17 16 38

From Messages paste only pasting the first number

We have a IOS React Native App that contains a webview, that webview shows this react-pin-input, however this compoent does not seem play nicely with the IOS 'From Messages' feature, where you can paste in the code sent in a SMS message. Only the first number is pasted - i have provided a couple of screengrabs illustrating the issue
Screenshot 2024-01-11 at 11 41 07
Screenshot 2024-01-11 at 11 48 01

Option to set initial value

Thank you for authoring and maintaining this component.

One request: is it possible to add support for setting an initial PIN value? Right now, there is no straightforward way to set the values programmatically. Happy to submit a pull request, if this is something you are open to including.

Cannot be used as a JSX component

I get this error
"'PinInput' cannot be used as a JSX component.
Its instance type 'PinInput' is not a valid JSX element."
on version 1.0.4

ReferenceError: window is not defined after update to 1.1.0 version

I use Next.js (v. 11.1.2)
After updating react-pin-input to the 1.1.0 version yarn build started to fail with the following error.

ReferenceError: window is not defined
    at Object.<anonymous> (/Users/dro/work/rubyroid/italbazar/frontend/node_modules/react-pin-input/dist/bundle.js:1:216)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.17049 (/Users/dro/work/rubyroid/italbazar/frontend/.next/server/pages/_app.js:3804:18)
    at __webpack_require__ (/Users/dro/work/rubyroid/italbazar/frontend/.next/server/webpack-runtime.js:25:42)
    at Object.57080 (/Users/dro/work/rubyroid/italbazar/frontend/.next/server/pages/_app.js:718:33) {
  type: 'ReferenceError'
}

Rollback to version 1.0.1 resolves the issue

Allow copy > paste

Be great if could allow to copy and code then paste into first input and for the rest of the inputs fill with the correct number.

Disable autocomplete password

Hey, is it possible to disable chrome's autocomplete password?

Any time I try writing in the pin item, it shows the dialog to fill in from passwords.

In plain HTML I tend to use autoComplete="new-password", seems to do the job.

Unable to change or override default styles

Hello.

Like the title says, I am unable to style the boxes. Overriding the default styles in a new .scss file does not work. Neither does the CSS in JSX method works. Even doing 'display: none' on the component has no effect whatsoever.

Kindly guide me on how to do it. Thank you.

Cant loose Focus programatically

using "OnComplete" function, I am trying to focus on the next input element on my webpage, however, I am not able to focus. It only works when the last character in pin input is removed and added again. but not the first time.

Pin Input somehow maintains the focus unless manually clicked somewhere in the background.

Unable to use asterisk (*) in place of dots(.)

Hi,
we are using react-pin-input package with our project.
we had a requirement of showing asterisk in place of dots when user gives the Pin.
tried of overriding or doing some hack kind of thing to resolve, but none of them worked.
Can you help us by providing the feature of using asterisk within the package.

elem.clear() not clearing the last digit

I try to clear the input fields after onComplete is called

<PinInput
        length={4}
        type="numeric"
        ref={p => pin = p}
        onComplete={(value) => {
          // debugger
          pin.clear()
          props.onComplete(value)
        }}
      />

It clears the first three digits but not for the last input field.
Please see the image.
screenshot from 2018-01-02 12-01-51

Unable to manipulate CSS/styling for the placeholder

The placeholder is created in a shadow DOM right now and there's no way to modify the styling.

Please at least add "part" attributes on the elements within the shadow DOM to allow developers to customize the stylings.

Or, another alternative is to add another props like "placeholderStyle".

Chrome autosave password is not disabled

Autosave of pin entered in the boxes is enabled in the package.

Is there a way to disable the chrome autofill behavior if the PIN value is entered and submitted?

Controlled Component

I need to include this as a controlled component for use in forms, (inside a wrapped field with something like React Final Form),

As such the initialvalue may change (say for instance via form reset).

Once the object is rendered, change to initialvalue has no effect

Can you please expose a method (like ref.clear()) to set the current value, that way I can use a react side effect to listen to changes in my wrapped component, and then inject these changes into your pin code component.

Thanks.

Numeric input doesnt display numeric keyboard

Hi,

First of all thank you for the module :)

Even though I put "numeric" as type for the input, the keyboard is not numeric at all for Android, and starts as numeric for Iphone, but then switches back to letters after one input.

Thanks for your help,

Antoine

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.