• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

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

almost 3 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();
  }
});
almost 3 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()"

almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error