From ce26b706c65c3b211bbab5891097830d4f560622 Mon Sep 17 00:00:00 2001 From: rizky Date: Fri, 25 Oct 2024 13:33:30 -0700 Subject: [PATCH] checkpoint --- comps/form/field/type/TypeOTP.tsx | 15 ++++++--------- preset/menu/Menu.tsx | 2 -- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/comps/form/field/type/TypeOTP.tsx b/comps/form/field/type/TypeOTP.tsx index 820710b..d295124 100755 --- a/comps/form/field/type/TypeOTP.tsx +++ b/comps/form/field/type/TypeOTP.tsx @@ -15,13 +15,6 @@ export const FieldOTP: FC<{ ref: [] as HTMLInputElement[], }); - // useEffect(() => { - // if (typeof fm.data[field.name] === "string") { - // local.otp = fm.data[field.name].split(""); - // local.render(); - // } - // }, [fm.data[field.name]]); - if (local.otp.length === 0 && digit) { for (let i = 0; i < digit; i++) { local.otp.push(""); @@ -65,9 +58,13 @@ export const FieldOTP: FC<{ }} onKeyDown={async (e) => { if (e.key === "Backspace") { - local.otp[idx] = ""; + let _idx = idx; + if (local.otp[_idx].length === 0) { + _idx--; + } + local.otp[_idx] = ""; local.render(); - const ref = local.ref[idx - 1]; + const ref = local.ref[Math.max(0, _idx - 1)]; if (ref) { ref.focus(); } diff --git a/preset/menu/Menu.tsx b/preset/menu/Menu.tsx index fdfdd8a..ca360be 100755 --- a/preset/menu/Menu.tsx +++ b/preset/menu/Menu.tsx @@ -3,8 +3,6 @@ import { useLocal } from "lib/utils/use-local"; import get from "lodash.get"; import { FC, useEffect, useRef } from "react"; import { IMenu, MenuProp } from "./utils/type-menu"; -import { LinkParam } from "lib/comps/form/field/type/TypeLink"; -import { hashSum } from "lib/utils/hash-sum"; // import { icon } from "../../.."; const local_default = {