Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AutoFill doesn't work correctly on Safari #80

Closed
hraboviyvadim opened this issue Sep 16, 2023 · 9 comments · Fixed by #94
Closed

AutoFill doesn't work correctly on Safari #80

hraboviyvadim opened this issue Sep 16, 2023 · 9 comments · Fixed by #94
Assignees
Labels
bug Something isn't working

Comments

@hraboviyvadim
Copy link

Hi! Thanks for this lib, its awesome! But there is an issue which seems to be critical.
In Safari (both mobile and desktop) autoFill works incorrect - it inserts code from sms in first input ignoring others:

image

Also, same issue when you get one-time-code from email (new feature from MacOS Sonoma, Safari 17):
image

I've tried to debug a little and it seems onChange event doesn't fire for autofill.

@soywod
Copy link
Owner

soywod commented Sep 17, 2023 via email

@hraboviyvadim
Copy link
Author

Yes, its 3.1.4.

I'll try to debug more. Hope to get some free time this week. I'll let you know if will figure out something.

@hraboviyvadim
Copy link
Author

@soywod I've been playing around with this issue locally and figured out that using onChange for inputs with same handler as for onPaste makes it work for autoFill in Safari 17.
Are there any reasons why you didn't use onChange for tracking input value changes?

pin-field.tsx

 ...
  const handleChange = (idx: number) => {
    return function (evt: React.ChangeEvent<HTMLInputElement>) {
      evt.preventDefault();
      const val = evt.target.value;

      dispatch({ type: 'handle-paste', idx, val });
    };
  };

  return (
    <>
      {range(0, codeLength).map((idx) => (
        <input
          type="text"
          autoCapitalize="off"
          autoCorrect="off"
          autoComplete="off"
          inputMode="text"
          {...inputProps}
          key={idx}
          ref={setRefAtIndex(idx)}
          autoFocus={hasAutoFocus(idx)}
          onFocus={handleFocus(idx)}
          onKeyDown={handleKeyDown(idx)}
          onKeyUp={handleKeyUp(idx)}
          onPaste={handlePaste(idx)}
          onChange={handleChange(idx)}
        />
      ))}
    </>
  );
...

@soywod
Copy link
Owner

soywod commented Sep 20, 2023 via email

@enobrev
Copy link

enobrev commented Oct 11, 2023

That seems reasonable as to why you're using the other listeners, but @hraboviyvadim was not suggesting replacing the existing listeners, but rather including an additional onChange listener as well.

Are there issues with adding the onChange handler as well?

@soywod
Copy link
Owner

soywod commented Nov 3, 2023 via email

@soywod
Copy link
Owner

soywod commented Jan 2, 2025

I have finally time to take care of this issue. I let you know whenever I have sth to show.

@soywod soywod mentioned this issue Jan 7, 2025
@soywod soywod closed this as completed in #94 Jan 7, 2025
@soywod
Copy link
Owner

soywod commented Jan 7, 2025

The v4.0.0 has been released. See #94 for more context, and the CHANGELOG for breaking changes documentation. The issue may have been fixed, because the PIN field relies now on the native onChange rather than key down, could someone confirm?

@soywod soywod reopened this Jan 7, 2025
@soywod
Copy link
Owner

soywod commented Jan 7, 2025

I was able to try on a recent iOS (on Safari) and it worked as expected 🎉

@soywod soywod closed this as completed Jan 7, 2025
@soywod soywod added the bug Something isn't working label Jan 7, 2025
@soywod soywod self-assigned this Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants