Skip to content

Commit d65bf88

Browse files
author
aoi-dev-0411
committed
feat: add auto-focus to first username input on page load (closes #36)
1 parent f5137b5 commit d65bf88

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

components/compare-form.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState } from "react";
1+
import { useState, useRef, useEffect } from "react";
22
import { Button } from "./ui/button";
33
import { ArrowLeftRight, RefreshCw } from "lucide-react";
44
import {
@@ -29,6 +29,12 @@ export function CompareForm({
2929
}: CompareFormProps) {
3030
const [username1, setUsername1] = useState("pbiggar");
3131
const [username2, setUsername2] = useState("CoralineAda");
32+
const firstInputRef = useRef<HTMLInputElement>(null);
33+
34+
// Auto-focus first input on page load
35+
useEffect(() => {
36+
firstInputRef.current?.focus();
37+
}, []);
3238

3339
const canSubmit = Boolean(username1.trim() && username2.trim() && !loading);
3440

@@ -63,6 +69,7 @@ export function CompareForm({
6369
<div className="grid gap-3 md:grid-cols-2">
6470
<input
6571
className="h-11 rounded-lg border border-slate-200 px-3 text-sm focus:outline-none focus:ring-2 focus:ring-primary/60 focus:border-transparent bg-white"
72+
ref={firstInputRef}
6673
placeholder={"Username 1 (e.g., torvalds)"}
6774
value={username1}
6875
onChange={(e) => setUsername1(e.target.value)}

0 commit comments

Comments
 (0)