From b844903b9436adc5d3c955984092e6b76c0d70ea Mon Sep 17 00:00:00 2001 From: Nate Lubeck Date: Sun, 1 Oct 2023 10:01:16 -0700 Subject: [PATCH 1/2] refactor(react): increased readability on OTP Input component --- packages/react/src/components/OTPInput.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/react/src/components/OTPInput.tsx b/packages/react/src/components/OTPInput.tsx index 9b4d0cde7da..e3bdfd0f05b 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); @@ -97,7 +97,7 @@ export function OTPInput(props: { value = value[value.length - 1]; } - if (!/[0-9]/.test(value) && value !== "") { + if (!/\d/.test(value) && value !== "") { e.preventDefault(); return; } From 75a568857081abbe30bb6924bd3cf23d35319030 Mon Sep 17 00:00:00 2001 From: Nate Lubeck Date: Sun, 1 Oct 2023 10:43:17 -0700 Subject: [PATCH 2/2] added missing changeset --- .changeset/strong-ghosts-leave.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/strong-ghosts-leave.md 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