Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

102
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda