add: auto focus to password and otp fields

This commit is contained in:
Mahyar Khanbolooki
2025-07-02 01:03:24 +03:30
parent ed1eb8a1ed
commit 1717d0b503
3 changed files with 4 additions and 1 deletions
+2 -1
View File
@@ -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}