fix: farsi digits and autofoucs in digits input
This commit is contained in:
@@ -8,6 +8,7 @@ import React, {
|
||||
} from 'react';
|
||||
import { TextField, Stack } from '@mui/material';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { replacePersianWithRealNumbers } from '@/utils/replacePersianWithRealNumbers';
|
||||
|
||||
interface DigitInputProps {
|
||||
error: boolean;
|
||||
@@ -34,6 +35,8 @@ const DigitInput: React.FC<DigitInputProps> = ({
|
||||
};
|
||||
|
||||
const handleChange = (value: string, index: number) => {
|
||||
value = replacePersianWithRealNumbers(value);
|
||||
|
||||
if (!/^\d$/.test(value) && value !== '') return;
|
||||
|
||||
const newCode = [...code];
|
||||
@@ -91,6 +94,7 @@ const DigitInput: React.FC<DigitInputProps> = ({
|
||||
color={success ? 'success' : 'primary'}
|
||||
key={index}
|
||||
inputRef={(el) => (inputRefs.current[index] = el)}
|
||||
autoFocus={index === 0}
|
||||
value={digit}
|
||||
onChange={(e) => handleChange(e.target.value, index)}
|
||||
onKeyDown={(e) => e.key === 'Backspace' && handleBackspace(e, index)}
|
||||
|
||||
Reference in New Issue
Block a user