Skip to content

Commit

Permalink
feat(Auth): added the reset button and fix the padding of inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
Anishali2 committed Feb 16, 2024
1 parent 886ccd3 commit 2cf10ef
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion apps/web/app/[locale]/auth/passcode/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ function PasscodeScreen({ form, className }: { form: TAuthenticationPasscode } &
</div>

<AuthCodeInputField
inputsRef={inputsRef}
inputReference={inputsRef}
key={form.authScreen.screen}
allowedCharacters="alphanumeric"
length={6}
Expand Down
9 changes: 5 additions & 4 deletions apps/web/lib/components/inputs/auth-code-input.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use client';

import { clsxm } from '@app/utils';
import React, { forwardRef, useEffect, useImperativeHandle } from 'react';
import React, { MutableRefObject, forwardRef, useEffect, useImperativeHandle, useRef } from 'react';
import { InputField } from './input';
import { useTranslations } from 'next-intl';

const allowedCharactersValues = ['alpha', 'numeric', 'alphanumeric'] as const;

export type AuthCodeProps = {
inputsRef: MutableRefObject<HTMLInputElement[]>;
inputReference?: MutableRefObject<HTMLInputElement[]>;
allowedCharacters?: (typeof allowedCharactersValues)[number];
ariaLabel?: string;
autoFocus?: boolean;
Expand Down Expand Up @@ -65,7 +65,7 @@ const propsMap: { [key: string]: InputProps } = {
export const AuthCodeInputField = forwardRef<AuthCodeRef, AuthCodeProps>(
(
{
inputsRef,
inputReference = null,
allowedCharacters = 'alphanumeric',
ariaLabel,
autoFocus = true,
Expand All @@ -89,7 +89,8 @@ export const AuthCodeInputField = forwardRef<AuthCodeRef, AuthCodeProps>(
if (!allowedCharactersValues.some((value) => value === allowedCharacters)) {
throw new Error(t('errors.INVALID_ALLOWED_CHARACTER'));
}

const reference = useRef<HTMLInputElement[]>([]);
const inputsRef = inputReference || reference;
const inputProps = propsMap[allowedCharacters];
const validDefaultValue =
defaultValue && defaultValue.length === length && defaultValue.match(inputProps.pattern) ? true : false;
Expand Down

0 comments on commit 2cf10ef

Please sign in to comment.