diff --git a/src/components/MagicCodeInput.js b/src/components/MagicCodeInput.js index 32c7ec21a920..4caa7328b92c 100644 --- a/src/components/MagicCodeInput.js +++ b/src/components/MagicCodeInput.js @@ -106,10 +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(''); + focusMagicCodeInput(); }, clear() { setInput(''); 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(() => {