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

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

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