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

127
Vistas
Changing <input type= color> behaviour from single click to double click

By default clicking a will bring up a window that lets you pick a custom colour.

I want to do this with a double click instead.

I can stop single click from working with e.preventDefault but I can't work out how to make doubleClick do this behaviour instead.

What I want:

handleDbClick = (e) => {
  //opens colour selection box
}
<input type="color" onDoubleClick={this.handleDbClick}/>

Solution:

handleClick = (e) => {
  if(e.detail === 1) {
     e.preventDefault()
     //do stuff for one click
  }
  //open colour selection box
}

<input type="color" onClick={this.handleClick} />

Thanks

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

What about something like this:

 const colorInput = document.getElementById("colorInput")
        let count = 0;
        let interval
        
        colorInput.addEventListener('click', e => {
            count++
            clearInterval(interval)
            interval = setInterval(() => {
             count = 0   
            }, 300)
            if(count === 2) {
                count = 0
            } else {

                e.preventDefault();
            }
        })

or this:

const colorInput = document.getElementById("colorInput")
        
        colorInput.addEventListener('click', e => {
            if(event.detail !== 2) {
                e.preventDefault()
            }
        })
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can simply use event.detail to check number of consecutive clicks, and use event.preventDefault() if they are not 2.

let input = document.querySelector("#colorInput");
input.addEventListener("click", (e) => {
  if (e.detail !== 2) e.preventDefault();
});
<input type="color" id="colorInput">

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