Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

283
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!