From ef1ea18a2f33c62837affaf13c04d9a868528eca Mon Sep 17 00:00:00 2001 From: "sarina.m" Date: Thu, 15 May 2025 22:27:49 +0330 Subject: [PATCH 1/3] fix: enhance OTP input handling for iOS and improve focus behavior --- src/components/single-otp-input.vue | 40 ++++++++++++++----------- src/components/vue3-otp-input.vue | 45 ++++++++++++++++------------- 2 files changed, 48 insertions(+), 37 deletions(-) diff --git a/src/components/single-otp-input.vue b/src/components/single-otp-input.vue index a45f35a..881706e 100644 --- a/src/components/single-otp-input.vue +++ b/src/components/single-otp-input.vue @@ -69,23 +69,29 @@ const isCodeNumeric = (charCode: number) => (charCode >= 48 && charCode <= 57) || (charCode >= 96 && charCode <= 105); // numeric keys and numpad keys -const handleOnKeyDown = (event: KeyboardEvent) => { - if (props.isDisabled) { - event.preventDefault(); - } - // Only allow characters 0-9, DEL, Backspace, Enter, Right and Left Arrows, and Pasting - const keyEvent = event || window.event; - const charCode = keyEvent.which ? keyEvent.which : keyEvent.keyCode; - if ( - isCodeNumeric(charCode) || - (props.inputType === "letter-numeric" && isCodeLetter(charCode)) || - [8, 9, 13, 37, 39, 46, 86].includes(charCode) - ) { - emit("on-keydown", event); - } else { - keyEvent.preventDefault(); - } -}; + const handleOnKeyDown = (event: KeyboardEvent) => { + if (props.isDisabled) { + event.preventDefault(); + } + // Only allow characters 0-9, DEL, Backspace, Enter, Right and Left Arrows, and Pasting + const keyEvent = event || window.event; + const charCode = keyEvent.which ? keyEvent.which : keyEvent.keyCode; + // Allow any input on iOS + if (/iPhone|iPad|iPod/.test(navigator.userAgent)) { + emit('on-keydown', event); + return; + } + + if ( + isCodeNumeric(charCode) || + (props.inputType === 'letter-numeric' && isCodeLetter(charCode)) || + [8, 9, 13, 37, 39, 46, 86].includes(charCode) + ) { + emit('on-keydown', event); + } else { + keyEvent.preventDefault(); + } + }; const handleOnPaste = (event: ClipboardEvent) => emit("on-paste", event); diff --git a/src/components/vue3-otp-input.vue b/src/components/vue3-otp-input.vue index 2ea098b..e83ced3 100644 --- a/src/components/vue3-otp-input.vue +++ b/src/components/vue3-otp-input.vue @@ -1,6 +1,5 @@