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

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

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 Denunciar

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 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