mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 18:33:01 +00:00
automatically focus first input
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { type ChangeEvent, useMemo, useState } from "react";
|
/** biome-ignore-all lint/correctness/useExhaustiveDependencies: <> */
|
||||||
|
import { type ChangeEvent, useEffect, useMemo, useState } from "react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
@@ -140,6 +141,17 @@ export default function LogInForm() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const focusFirstInput = () => {
|
||||||
|
const firstInput = document.querySelector("input");
|
||||||
|
if (firstInput) {
|
||||||
|
(firstInput as HTMLInputElement).focus();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
focusFirstInput();
|
||||||
|
}, []);
|
||||||
|
|
||||||
const resetForm = () => {
|
const resetForm = () => {
|
||||||
setError("");
|
setError("");
|
||||||
setSubmitAttempted(false);
|
setSubmitAttempted(false);
|
||||||
@@ -147,6 +159,8 @@ export default function LogInForm() {
|
|||||||
setNameTouched(false);
|
setNameTouched(false);
|
||||||
setUsernameTouched(false);
|
setUsernameTouched(false);
|
||||||
setPasswordTouched(false);
|
setPasswordTouched(false);
|
||||||
|
|
||||||
|
requestAnimationFrame(() => focusFirstInput());
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = (e: React.FormEvent) => {
|
const handleSubmit = (e: React.FormEvent) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user