I'm using material-ui in my react project. I wanna copy a number and paste in multiple text fields.
const [otpArr, setOtpArr] = useState<string[]>(['', '', '', '', '', ''])
let inputRefs = useRef([React.createRef<HTMLDivElement>(), React.createRef<HTMLDivElement>(), React.createRef<HTMLDivElement>(), React.createRef<HTMLDivElement>(), React.createRef<HTMLDivElement>(), React.createRef<HTMLDivElement>()])
{otpArr && otpArr.map((x, index) => (
<NumberTextField
inputRef={inputRefs.current[index]}
variant='outlined'
size='small'
id='otp'
value={x}
key={index}
onChange={(e: any) => {
const temp = [...otpArr]
temp[index] = e.target.value
setOtpArr(temp)
if ((index < otpArr.length - 1) && e.target.value.length === 1) {
inputRefs.current[index + 1]?.current?.focus()
}
}}
inputProps={{ maxLength: 1 }}
style={{
width: '3rem',
direction: 'ltr',
marginTop: '3rem',
}}
/>
))}
any solution?