Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

220
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda