react-auth-code-input icon indicating copy to clipboard operation
react-auth-code-input copied to clipboard

Autocomplete one-time-code not working on Chrome

Open Rty-i4 opened this issue 2 years ago • 11 comments

Hi, Safari works without any issues. However, in Chrome, when passing one-time-code, it fills only the first number and leaves the rest empty.

Rty-i4 avatar Apr 13 '22 10:04 Rty-i4

Hi @Rty-i4 I was able to reproduce the issue, I'll be checking it this week, I just hope to find an easy way to test it 😅

drac94 avatar Apr 25 '22 20:04 drac94

After reviewing this I realized chrome is not firing the onPaste event when filling the input using an SMS, I tried to find a quick fix but until now I haven't had luck, it seems like this will need a more significant effort to be solved 😞

drac94 avatar Jul 08 '22 15:07 drac94

@drac94 Hey brother, have you find any solution for that? If yes, would you mind sharing it with me? I will be highly appreciate it.

Prasannsitani avatar Oct 25 '22 07:10 Prasannsitani

Do you have any updates or ideas on how to fix this? I will appreciate it so much.

n1arash avatar Jan 13 '23 13:01 n1arash

Sorry all, I haven't had time to work on this, I'll try to allocate some time next week, also PR's are welcomed

drac94 avatar Jan 20 '23 19:01 drac94

hi dear @drac94 hope you doing well adding onInput handler to input with basically pasteHandler code fixed pasting issue with phone keyboards:

    const handleOnInput = (event: ChangeEvent<HTMLInputElement>) => {
      if (!event.target.value) return;
      const {
        target: { value },
      } = event;
      let currentInput = 0;

      if (event.target.value && event.target.value.length === length) {
        for (let i = 0; i < value.length; i++) {
          const pastedCharacter = value.charAt(i);
          if (pastedCharacter.match(inputProps.pattern)) {
            inputsRef.current[currentInput].value = pastedCharacter;
            if (inputsRef.current[currentInput].nextElementSibling !== null) {
              (
                inputsRef.current[currentInput]
                  .nextElementSibling as HTMLInputElement
              ).focus();
              currentInput++;
            }
          }
        }
        sendResult();
      }
    };

I will make a PR soon for it

EDIT: you must remove maxLength props to use this handler function

n1arash avatar Jan 23 '23 02:01 n1arash

Also having this issue - noticed the same, onPaste not firing. Looks like @n1arash may have a solution though. Thanks :)

Sandy-Garrido avatar Jan 25 '23 15:01 Sandy-Garrido

@Sandy-Garrido hello, the onPaste problem is because the phone keyboard pasting functionality doesn't paste on the input it simulates the user typing on inputs and filling each input manually, onInput event handles all kinds of changes on input (pasting/typing, etc...)

n1arash avatar Jan 28 '23 12:01 n1arash

EDIT: you must remove maxLength props to use this handler function

@n1arash could removing maxLength affect something else?

Also I'm thinking on how could we easily test this 🤔 right now I am doing it manually

drac94 avatar Jan 28 '23 15:01 drac94

@drac94 What is the status of fixing it?

michalm55 avatar Nov 12 '23 13:11 michalm55

Hi all. Created pull request with @n1arash solution: https://github.com/drac94/react-auth-code-input/pull/66

AliaksandrKazerski avatar Dec 07 '23 12:12 AliaksandrKazerski