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

218
Visualizações
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 à 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