File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import { useState } from "react" ;
1+ import { useState , useRef , useEffect } from "react" ;
22import { Button } from "./ui/button" ;
33import { ArrowLeftRight , RefreshCw } from "lucide-react" ;
44import {
@@ -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 ) }
You can’t perform that action at this time.
0 commit comments