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

222
Views
React: How to navigate through list in a table by arrow keys without triggering the scrollbar moving up and down?

I have built a table component with a list of items in it. By defining hotkeys with the react-hotkeys package, I can navigate through the list with the 'arrow up' and 'arrow down' keys. However, I do have a scroll bar on the right side of the screen. Whenever I use the hotkeys, the screen will scroll at the same time. How can I navigate through items with the hotkey without triggering the scrollbar unless the item is out of the current screen?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can easily prevent the default browser scroll behavior on the event keydown when the key is arrow up or arrow down. This post explains how to do this.

For your specific needs to disable / enable it whether the table is in the viewport or not, you could check if it is in the event.

const table = document.querySelector('#table-id')

window.addEventListener("keydown", function(e) {
    if(["Space","ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].indexOf(e.code) > -1) {
        const y = table.getBoundingClientRect().y
        if (y > 0 && y < window.innerHeight) { // Table is in viewport.
            e.preventDefault();
        }
    }
}, false);
about 4 years ago · Santiago Trujillo 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!