fix(TOTPForm): focus to code after fail

This commit is contained in:
Stephen Zhou 2025-01-17 23:38:51 +08:00
parent 6b884d1fd7
commit 8be6c13a76
No known key found for this signature in database
1 changed files with 6 additions and 2 deletions

View File

@ -79,11 +79,15 @@ export function TOTPForm({
onError: (error) => {
const { code } = getFetchErrorInfo(error)
if (error.message === "invalid two factor authentication" || code === 4007) {
form.resetField("code" as any)
form.setError("code" as any, {
form.resetField("code")
form.setError("code", {
type: "manual",
message: t("profile.totp_code.invalid"),
})
// Avoid calling setFocus right after reset as all input references will be removed by reset API.
setTimeout(() => {
form.setFocus("code")
}, 10)
controls.start("shake")
}
},