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

284
Visualizações
Javascript event.preventDefault() not working on modal

I am working in Angular to implement accessibility and adding (keyup.space) events on clickable elements. Space press has a default behavior that moves the scrollbar, which I don't want to happen. I managed to skip it in the main page by using event.preventDefault(), but when I press space in a button in the modal the behavior is present although I use event.preventDefault().

Is there any way to stop the default behavior of moving the scrollbar when I press space in an element in the modal?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

If it is vanilla js, it should work as expected.

https://jsfiddle.net/ramseyfeng/xpd832mk/

window.addEventListener('keydown', function(e) {
  if(e.keyCode === 32) {
    e.preventDefault();
  }
});
about 4 years ago · Juan Pablo Isaza Relatório

0

I was using (keyup.space)="$event.preventDefault();onClickMethod()" event. I fixed it by using (keydown.space)=="$event.preventDefault();onClickMethod()"

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