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

Passcodes | Auto submit form on paste or change when valid #3052

Merged
merged 2 commits into from
Feb 5, 2025

Conversation

coldlink
Copy link
Member

@coldlink coldlink commented Feb 4, 2025

What does this change?

Currently the reader has to manually submit the code after typing it in or pasting it in.

To make it faster for the reader, this PR updates the functionality to automatically submit the code when it reaches 6 digits long or pasting it in.

We added checks to make sure that the auto-submission is disabled for specifc scenarios

  • If there is an error on the field
  • If the reader hasn't previously interacted with the field
  • If the value isn't a 6 digit number

It is also disabled in scenarios where formRef isn't passed in.

Speaking of which, a minor refactor had to be performed on the MainForm to make formRef a parameter instead. This allows us to pass in a ref for the MainForm, so it can be used in other components, specifically in this scenario the PasscodeInput component.

Finally PasscodeEmailSent page was updated to create the new formRef and pass it to both MainForm and PasscodeInput

Previous Auto submit - onChange Auto submit - onPaste Auto submit - disabled after error
Screen.Recording.2025-02-04.at.08.52.11.mov
Screen.Recording.2025-02-04.at.09.00.35.mov
Screen.Recording.2025-02-04.at.08.59.09.mov
Screen.Recording.2025-02-04.at.09.01.25.mov

Tested

  • DEV
  • CODE
    • Chrome Web
    • Chrome Mobile
    • Firefox Web
    • Firefox Mobile
    • Safari Web
    • Safari Mobile

@coldlink coldlink added the passwordless PRs/Issues related to passwordless/passcode functionality label Feb 4, 2025
@coldlink coldlink marked this pull request as ready for review February 4, 2025 09:02
@coldlink coldlink requested a review from a team as a code owner February 4, 2025 09:02
@coldlink coldlink force-pushed the mm/auto-submit-code branch from 79dce06 to edd2687 Compare February 4, 2025 10:18
@coldlink coldlink requested review from a team and removed request for a team February 4, 2025 10:23
AshCorr
AshCorr previously approved these changes Feb 5, 2025
@@ -8,6 +8,7 @@ import { remSpace } from '@guardian/source/foundations';
interface PasscodeInputProps extends TextInputProps {
passcode?: string;
fieldErrors?: FieldError[];
formRef?: React.RefObject<HTMLFormElement | null>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this ever be undefined?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way it's currently being used, it's always defined, so will refactor that.

@@ -112,6 +112,7 @@ export const PasscodeEmailSent = ({
const [recaptchaErrorMessage, setRecaptchaErrorMessage] = useState('');
const [recaptchaErrorContext, setRecaptchaErrorContext] =
useState<ReactNode>(null);
const formRef = createRef<HTMLFormElement>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use useRef instead as we're using function components
as per
https://react.dev/reference/react/createRef

image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good spot! I'll try and refactor it!

@coldlink coldlink enabled auto-merge February 5, 2025 14:18
@coldlink coldlink merged commit 055c91d into main Feb 5, 2025
21 checks passed
@coldlink coldlink deleted the mm/auto-submit-code branch February 5, 2025 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
passwordless PRs/Issues related to passwordless/passcode functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants