fix: OTP auto-submit not firing when typing manually

String.includes("") always returns true in JavaScript, so the condition
`!newValue.includes("")` was always false, preventing onComplete from
ever firing on manual input. Only paste worked because it uses a
separate code path. The length check alone is sufficient since empty
digits produce a shorter joined string.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
ramirez 2026-03-05 18:31:19 +09:00
parent 9754c73b64
commit 6be28b4fb5

View File

@ -65,7 +65,7 @@ function useOtpHandlers({
const newValue = newDigits.join(""); const newValue = newDigits.join("");
onChange(newValue); onChange(newValue);
if (char && index < length - 1) focusInput(index + 1); if (char && index < length - 1) focusInput(index + 1);
if (newValue.length === length && !newValue.includes("")) onComplete?.(newValue); if (newValue.length === length) onComplete?.(newValue);
}, },
[digits, length, onChange, onComplete, focusInput] [digits, length, onChange, onComplete, focusInput]
); );