Skip to content

Commit bda99c1

Browse files
committed
fix(#112): use correct keyboard type for otp input
1 parent 857b31b commit bda99c1

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

lint-staged.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default {
77
'projects/**/*.{ts,tsx}': [
88
'yarn codegen:styles',
99
(files) => `yarn nx affected --target=typecheck --files=${files.join(',')}`,
10-
(files) => `yarn test run ${files.join(' ')}`,
10+
'yarn test run --changed',
1111
],
1212
'projects/**/*.{js,ts,jsx,tsx,json}': (files) => [
1313
`yarn format --files ${files.join(',')}`,

projects/app-web/app/routes/account_verify-2fa/route.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ export function AccountVerify2FARoute(props: Route.ComponentProps) {
250250
...getInputProps(fields.code, { type: 'text' }),
251251
autoComplete: 'one-time-code',
252252
autoFocus: true,
253+
mode: 'numeric',
253254
}}
254255
/>
255256
<input {...getInputProps(fields.target, { type: 'hidden' })} />

projects/app-web/app/routes/verify-otp/route.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,20 @@ const INSTRUCTION_BY_TYPE: Record<VerificationType, string> = {
188188
'To enable two-factor authentication, please enter your six digit code from your authenticator app',
189189
};
190190

191+
const OTP_INPUT_MODE_BY_TYPE: Record<
192+
VerificationType,
193+
'alphanumeric' | 'numeric'
194+
> = {
195+
[VerificationType.ChangeEmail]: 'numeric',
196+
[VerificationType.ChangeEmailConfirmation]: 'alphanumeric',
197+
[VerificationType.ChangePassword]: 'numeric',
198+
[VerificationType.Onboarding]: 'alphanumeric',
199+
[VerificationType.ResetPassword]: 'alphanumeric',
200+
[VerificationType.TwoFactorAuth]: 'numeric',
201+
[VerificationType.TwoFactorAuthDisable]: 'numeric',
202+
[VerificationType.TwoFactorAuthSetup]: 'numeric',
203+
};
204+
191205
const pageInfo = css({
192206
marginBottom: '8',
193207
textAlign: 'center',
@@ -240,6 +254,8 @@ export function VerifyOTPRoute(props: Route.ComponentProps) {
240254
? INSTRUCTION_BY_TYPE[type]
241255
: 'Please enter your verification code';
242256

257+
const otpInputMode = type ? OTP_INPUT_MODE_BY_TYPE[type] : 'numeric';
258+
243259
return (
244260
<>
245261
<section className={pageInfo}>
@@ -258,6 +274,7 @@ export function VerifyOTPRoute(props: Route.ComponentProps) {
258274
...getInputProps(fields[QueryParam.Code], { type: 'text' }),
259275
autoComplete: 'one-time-code',
260276
autoFocus: true,
277+
mode: otpInputMode,
261278
}}
262279
/>
263280
<input

projects/lib-design-system/src/components/otp-field/otp-field.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import * as React from 'react';
22
import { Field } from '@base-ui-components/react/field';
33
import { css, cx } from '@vers/styled-system/css';
4-
import { REGEXP_ONLY_DIGITS_AND_CHARS } from 'input-otp';
4+
import { REGEXP_ONLY_DIGITS, REGEXP_ONLY_DIGITS_AND_CHARS } from 'input-otp';
55
import { InputOTP } from './input-otp.tsx';
66

77
interface Props {
88
className?: string;
99
errors: Array<string>;
10-
inputProps: React.ComponentProps<typeof Field.Control>;
10+
inputProps: React.ComponentProps<typeof Field.Control> & {
11+
mode?: 'alphanumeric' | 'numeric';
12+
};
1113
}
1214

1315
const container = css({
@@ -49,15 +51,24 @@ export function OTPField(props: Props) {
4951
controlProps.onChange?.(event);
5052
};
5153

54+
const pattern =
55+
props.inputProps.mode === 'alphanumeric'
56+
? REGEXP_ONLY_DIGITS_AND_CHARS
57+
: REGEXP_ONLY_DIGITS;
58+
59+
const inputMode =
60+
props.inputProps.mode === 'alphanumeric' ? 'text' : 'numeric';
61+
5262
return (
5363
<InputOTP
5464
{...controlProps}
5565
autoCapitalize="off"
5666
autoComplete="off"
5767
autoCorrect="off"
5868
data-testid="otp-input"
69+
inputMode={inputMode}
5970
maxLength={6}
60-
pattern={REGEXP_ONLY_DIGITS_AND_CHARS}
71+
pattern={pattern}
6172
spellCheck={false}
6273
value={controlProps.value as string}
6374
onChange={onChange}

0 commit comments

Comments
 (0)