diff --git a/.changeset/strong-ghosts-leave.md b/.changeset/strong-ghosts-leave.md new file mode 100644 index 00000000000..22fb65681a6 --- /dev/null +++ b/.changeset/strong-ghosts-leave.md @@ -0,0 +1,5 @@ +--- +"@thirdweb-dev/react": patch +--- + +Refactored OTPInput component to be simpler to read diff --git a/packages/react/src/components/OTPInput.tsx b/packages/react/src/components/OTPInput.tsx index 8f99f120f3d..43131e5e0bb 100644 --- a/packages/react/src/components/OTPInput.tsx +++ b/packages/react/src/components/OTPInput.tsx @@ -36,7 +36,7 @@ export function OTPInput(props: { data-error={props.isInvalid} ref={(e) => (boxEls.current[i] = e)} key={i} - value={otp[i] === undefined ? "" : otp[i]} + value={otp[i] ?? ""} type="number" variant="outline" onPaste={(e) => { @@ -44,7 +44,7 @@ export function OTPInput(props: { const newOTP = pastedData .slice(0, props.digits) .split("") - .filter((n) => /[0-9]/.test(n)) + .filter((n) => /\d/.test(n)) .map(Number); setOTP(newOTP); @@ -100,7 +100,7 @@ export function OTPInput(props: { } } - if (!/[0-9]/.test(value) && value !== "") { + if (!/\d/.test(value) && value !== "") { e.preventDefault(); return; }