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

103
Visualizações
Doubleclick in React

I created a div which contains an input component and set pointer-events to none. I wrote the code in such a way that when the user clicks anywhere in the div, the input gets the focus by using ref's. Now the problem is that when I double click on the typed text, instead of selecting the text the focus event is triggered and the cursor appears at the end of the text instead of selecting it. How can I revert back to the default behaviour?

<div className="flex relative" onClick={() => inputRef.current.focus()}>
    <input className="pointer-events-none" type='text' ref={inputRef} />
</div>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can check if the current clicked element is your input or not. If it is, you can ignore the focus logic

<div className="flex relative" onClick={(e) => {
   //if your current clicked element is not the input, it will execute `focus`
   if(e.target !== inputRef.current) { 
      inputRef.current.focus() 
   }
}}>
    <input className="pointer-events-none" type='text' ref={inputRef} />
</div>
about 4 years ago · Juan Pablo Isaza Relatório
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