parent
903049f43b
commit
7dc86f0731
3 changed files with 83 additions and 14 deletions
@ -0,0 +1,58 @@ |
||||
import React from 'react'; |
||||
import './VerificationInput.css'; |
||||
|
||||
export default class VerificationInput extends React.Component { |
||||
|
||||
render() { |
||||
|
||||
const numOfFields = 3; |
||||
|
||||
const handleChange = e => { |
||||
const { maxLength, value, name } = e.target; |
||||
const [fieldName, fieldIndex] = name.split("-"); |
||||
|
||||
// Check if they hit the max character length
|
||||
if (value.length >= maxLength) { |
||||
// Check if it's not the last input field
|
||||
if (parseInt(fieldIndex, 10) < 4) { |
||||
// Get the next input field
|
||||
const nextSibling = document.querySelector( |
||||
`input[name=ssn-${parseInt(fieldIndex, 10) + 1}]` |
||||
); |
||||
|
||||
// If found, focus the next field
|
||||
if (nextSibling !== null) { |
||||
nextSibling.focus(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
return( |
||||
<div className='flex justify-between w-full'> |
||||
{[0,1,2,3].map((item, index) => ( |
||||
<input |
||||
name={`ssn-${index + 1}`} |
||||
|
||||
|
||||
class='code-input' className='h-12 w-12 bg-red46OP flex justify-center items-center text-center rounded-lg outline-1 focus:bg-white outline-red52' |
||||
type="text"
|
||||
id="verifyinpt" |
||||
required
|
||||
maxlength="1"
|
||||
onChange={handleChange} |
||||
onKeyPress={(evt) => {if (!/[0-9]/.test(evt.key)){evt.preventDefault();}}} |
||||
autoFocus={index == 0 && true}/> |
||||
)) |
||||
|
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div> |
||||
); |
||||
} |
||||
} |
Loading…
Reference in new issue