From 2eef6829126a6c7de20160255e088636a75b10a3 Mon Sep 17 00:00:00 2001 From: wikuskriek Date: Fri, 16 Jun 2023 09:58:07 +0200 Subject: [PATCH 1/2] fix: 2FA Input field not focused on mobile --- src/components/MagicCodeInput.js | 5 +++++ src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.js | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/MagicCodeInput.js b/src/components/MagicCodeInput.js index 32c7ec21a920..f13a4433c261 100644 --- a/src/components/MagicCodeInput.js +++ b/src/components/MagicCodeInput.js @@ -111,6 +111,11 @@ function MagicCodeInput(props) { setFocusedIndex(0); inputRefs.current[0].focus(); }, + resetFocus() { + setInput(''); + setFocusedIndex(0); + inputRefs.current[0].focus(); + }, clear() { setInput(''); setFocusedIndex(0); diff --git a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.js b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.js index 3133c6bd6693..11004ea932ae 100755 --- a/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.js +++ b/src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.js @@ -111,7 +111,7 @@ function BaseValidateCodeForm(props) { if (!input2FARef.current || prevRequiresTwoFactorAuth || !props.account.requiresTwoFactorAuth) { return; } - input2FARef.current.focus(); + input2FARef.current.resetFocus(); }, [props.account.requiresTwoFactorAuth, prevRequiresTwoFactorAuth]); useEffect(() => { From 7f8907f66d8bae674688d1fd445ab85788d9a28c Mon Sep 17 00:00:00 2001 From: wikuskriek Date: Fri, 16 Jun 2023 17:17:57 +0200 Subject: [PATCH 2/2] feat: focusMagicCodeInput function --- src/components/MagicCodeInput.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/MagicCodeInput.js b/src/components/MagicCodeInput.js index f13a4433c261..4caa7328b92c 100644 --- a/src/components/MagicCodeInput.js +++ b/src/components/MagicCodeInput.js @@ -106,15 +106,18 @@ function MagicCodeInput(props) { setFocusedIndex(undefined); }; + const focusMagicCodeInput = () => { + setFocusedIndex(0); + inputRefs.current[0].focus(); + }; + useImperativeHandle(props.innerRef, () => ({ focus() { - setFocusedIndex(0); - inputRefs.current[0].focus(); + focusMagicCodeInput(); }, resetFocus() { setInput(''); - setFocusedIndex(0); - inputRefs.current[0].focus(); + focusMagicCodeInput(); }, clear() { setInput('');