Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
React: programmatically focus library components?

I have a third-party radio button that loses tab focus when we interact with it via the keyboard; i.e. tabbing to it and then pressing enter causes the focus to move on to another element, when I want the focus to stay on the radio button. Is there a way to programmatically focus the radio button from inside its onChange handler? My code looks something like this, which doesn't work:

const Component = (event) =>{
   const handleChange = ()=>{
      //business logic
      event.target.focus()
   }
   return(<RadioBtn onChange={handleChange}/>)
}

I also tried using a ref but that didn't work either, did I do something wrong?

const Component = (event) =>{
   const rdbRef = useRef();

   const handleChange = ()=>{
      //business logic
      rdbRef.current.focus();
   }
   return(<RadioBtn 
           onChange={handleChange}
           ref={rdbRef}/>)
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!