react-otp-input icon indicating copy to clipboard operation
react-otp-input copied to clipboard

Add or expose key press or key down event

Open CaptainT33mo opened this issue 5 years ago • 9 comments

  • Describe the Feature Request I want to use the OTP input field without a form and want a key down or keypress event to track the Enter Key so that I can submit the value when the enter key is pressed.
  • Describe Preferred Solution
           ...
           onKeyDown={keydown}
           ...
       />```

CaptainT33mo avatar Feb 07 '20 09:02 CaptainT33mo

same here

iamaamir avatar Feb 13 '20 17:02 iamaamir

Same here

kumarsandeep91 avatar Sep 03 '20 06:09 kumarsandeep91

workaround: wrap the component in a div and put a keydown handler on that

ibash avatar Sep 04 '20 06:09 ibash

@ibash that workaround works well. Also, you can do the same thing by putting that component inside a form and listening to the onSubmit event of the form, which is what I did in my project.

CaptainT33mo avatar Sep 04 '20 11:09 CaptainT33mo

Hi, is this issue up for grabs? Then I would like to work on it.

g-ravity avatar Sep 30 '20 15:09 g-ravity

Do it!

ibash avatar Sep 30 '20 22:09 ibash

Okay, I'll start working on it.

g-ravity avatar Oct 01 '20 04:10 g-ravity

Is the issue still not done? I would like to take it

haseena-hassan avatar Oct 14 '20 09:10 haseena-hassan

Use it like this:

                      <div>
                        <form onSubmit={handleOtpSubmit}>
                          <OtpInput
                            hasErrored={hasErrored}
                            errorStyle='two-fa-otp-error'
                            value={otp}
                            onChange={handleChange}
                            numInputs={6}
                            isInputNum={true}
                            containerStyle='two-fa-otp-input'
                            shouldAutoFocus
                          />
                          <Button className='d-none' type='submit' />
                        </form>
                      </div>

that way, on enter, you will get event in handleOtpSubmit

denishrana09 avatar Oct 14 '21 08:10 denishrana09