Skip to content

Commit a692154

Browse files
authored
Fix OTP input entered by clicking on “from messages” option in iOS safari (#2936)
1 parent 1d327b6 commit a692154

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

.changeset/calm-grapes-rule.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Fix OTP input entered by by clicking on “from messages” option in iOS safari

.changeset/old-fans-destroy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@thirdweb-dev/react": patch
3+
---
4+
5+
Fix OTP input entered by by clicking on “from messages” option in iOS safari

legacy_packages/react/src/components/OTPInput.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,11 @@ export function OTPInput(props: {
9494
}
9595
}}
9696
onChange={(e) => {
97-
let value = e.target.value;
97+
const value = e.target.value;
9898

9999
if (value.length > 1) {
100-
const lastValue = value[value.length - 1];
101-
if (lastValue) {
102-
value = lastValue;
103-
}
100+
setOTP(value.split("").filter((n) => /\d/.test(n)).map(Number));
101+
return;
104102
}
105103

106104
if (!/\d/.test(value) && value !== "") {

packages/thirdweb/src/react/web/ui/components/OTPInput.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,11 @@ export function OTPInput(props: {
9696
}
9797
}}
9898
onChange={(e) => {
99-
let value = e.target.value;
99+
const value = e.target.value;
100100

101101
if (value.length > 1) {
102-
const lastValue = value[value.length - 1];
103-
if (lastValue) {
104-
value = lastValue;
105-
}
102+
setOTP(value.split(""));
103+
return;
106104
}
107105

108106
if (!/\d/.test(value) && value !== "") {

0 commit comments

Comments
 (0)