add: auto focus to password and otp fields
This commit is contained in:
@@ -12,7 +12,7 @@ type Props = {
|
||||
} & Omit<React.InputHTMLAttributes<HTMLInputElement>, "id">;
|
||||
|
||||
|
||||
function OTPInputField({ onChange, maxLength = 6, htmlFor, labelText, className, value = '', ...restProps }: Props) {
|
||||
function OTPInputField({ onChange, maxLength = 6, htmlFor, labelText, className, autoFocus, value = '', ...restProps }: Props) {
|
||||
const values = value?.toString().split('').slice(0, maxLength);
|
||||
const inputRefs = useRef(Array.from({ length: maxLength }, () => createRef<HTMLInputElement>()));
|
||||
const [prevLength, setPrevLength] = useState(0);
|
||||
@@ -58,6 +58,7 @@ function OTPInputField({ onChange, maxLength = 6, htmlFor, labelText, className,
|
||||
{inputRefs?.current?.map((ref, i) => {
|
||||
return (
|
||||
<input
|
||||
autoFocus={i == 0 && autoFocus}
|
||||
{...restProps}
|
||||
key={i}
|
||||
onKeyDown={keyDown}
|
||||
|
||||
Reference in New Issue
Block a user