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 { useEffect , useRef , useState } from "react" ;
22import { Button } from "./ui/button" ;
33import { ArrowLeftRight , RefreshCw } from "lucide-react" ;
44import {
@@ -29,6 +29,11 @@ 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+ useEffect ( ( ) => {
35+ firstInputRef . current ?. focus ( ) ;
36+ } , [ ] ) ;
3237
3338 const canSubmit = Boolean ( username1 . trim ( ) && username2 . trim ( ) && ! loading ) ;
3439
@@ -62,6 +67,7 @@ export function CompareForm({
6267 < CardContent >
6368 < div className = "grid gap-3 md:grid-cols-2" >
6469 < input
70+ ref = { firstInputRef }
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"
6672 placeholder = { "Username 1 (e.g., torvalds)" }
6773 value = { username1 }
You can’t perform that action at this time.
0 commit comments