Skip to content

Commit 1c270fa

Browse files
authored
Merge pull request #63 from sarinaa-m/non-English-char-number-in-ios-device
fix: enhance OTP input handling for iOS and improve focus behavior
2 parents 0ea5e0a + 70be99a commit 1c270fa

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/components/single-otp-input.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ const handleOnKeyDown = (event: KeyboardEvent) => {
7676
// Only allow characters 0-9, DEL, Backspace, Enter, Right and Left Arrows, and Pasting
7777
const keyEvent = event || window.event;
7878
const charCode = keyEvent.which ? keyEvent.which : keyEvent.keyCode;
79+
// Allow any input on iOS
80+
if (/iPhone|iPad|iPod/.test(navigator.userAgent)) {
81+
emit("on-keydown", event);
82+
return;
83+
}
84+
7985
if (
8086
isCodeNumeric(charCode) ||
8187
(props.inputType === "letter-numeric" && isCodeLetter(charCode)) ||

src/components/vue3-otp-input.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ const handleOnFocus = (index: number) => {
6868
activeInput.value = index;
6969
};
7070
const handleOnBlur = () => {
71-
activeInput.value = -1;
71+
// Don't reset activeInput if we're at the last input
72+
if (activeInput.value !== props.numInputs - 1) {
73+
activeInput.value = -1;
74+
}
7275
};
7376
7477
// Helper to return OTP from input
@@ -137,7 +140,10 @@ const handleOnPaste = (event: any) => {
137140
138141
const handleOnChange = (value: number | string) => {
139142
changeCodeAtFocus(value);
140-
focusNextInput();
143+
// Only move to next input if we're not at the last input
144+
if (activeInput.value < props.numInputs - 1) {
145+
focusNextInput();
146+
}
141147
};
142148
const clearInput = () => {
143149
if (otp.value.length > 0) {

0 commit comments

Comments
 (0)