Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

182
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda