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

216
Vistas
How to detect mouse right-click in Typescript

I'm trying to detect left and right mouse clicks. I have a div with an onClick handler attached to it. This is what it looks like:

<div className={styles.itemSlot} onClick={this.onClick}></div>

And this is what the 'onClick' looks like:

  private readonly onClick = (evt: React.MouseEvent<HTMLImageElement>) => {
    if (evt.button === 1) {
      console.log('Left Click')
    }
    if (evt.button === 2) {
      console.log('Right Click')
    }
  };

The left click gets detected, but when I click the right button on the mouse, nothing happens. The same is true for the wheel or middle button. Only the left click gets detected.

How can I fix this issue?

about 4 years ago · Juan Pablo Isaza
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