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

123
Visualizações
Pressing tab in Chrome focuses offscreen elements by forcibly moving elements, breaking page layout

Problem

When using transform: translate to animate a drawer in & out, pressing the tab key in Chrome will alter the layout of the page to bring the hidden drawer contents into focus.

The solution that almost works: add visibility: hidden to the drawer when it's closed, preventing its elements from being focusable. However the drawer must be visible during the close animation. Therefore pressing tab during the closing animation reproduces the issue.

Example

https://jsfiddle.net/uje5m1o8/6/

  1. Open the drawer
  2. Close the drawer
  3. While the drawer is in the middle of its closing animation, press tab a few times.

The toggle button's position is now permanently incorrect. It moves upward off screen.

Goal

I'm looking for a way to stop this from happening. I'd prefer for this to work with an arbitrary amount of contents within the drawer, so manually adding tabIndex=-1 to everything in the drawer isn't preferable.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Add a check to see if the animation is in progress and prevent navigation with tab during that time. There might be a nicer solution though.

let animInProg = false

const toggle = () => {
    anim()
    const drawer = document.querySelector('#drawer')
  drawer.classList.toggle('drawer-open')
  drawer.classList.toggle('drawer-closed')
}

const toggleButton = document.querySelector('#toggle-button')
toggleButton.addEventListener('click', toggle)

function anim(){
    animInProg = true;
    return setTimeout(()=>{
    animInProg = false;
  }, 500)
}

document.addEventListener('keydown', (e)=>{
    if(animInProg && e.key == 'Tab'){
    e.preventDefault()
  }
})
#interaction-box {
  width: 80%;
  height: 200px;
  margin: auto;
  background-color: cyan;
  position: relative;
  overflow: hidden;
}

#drawer {
  position: absolute;
  bottom: 0;
  background-color: red;
  width: 100%;
  height: 50%;
  
  display: flex;
  justify-content: center;
  align-items: flex-end;
}

.drawer-closed {
  transform: translateY(100%);
  visibility: hidden;
  transition: visibility 0ms 500ms, transform 500ms ease-in-out;
}

.drawer-open {
  transition: transform 500ms ease-in-out;
}
<div id="interaction-box">
  <button id="toggle-button">
    Toggle Drawer
  </button>
  <br />
  Text 1
  <br />
  Text 2
  <br />
  Text 3
  <br />
  Text 4
  <br />
  Text 5
  <br />
  Text 6
  <br />
  Text 7
  <br />
  Text 8
  <br />
  Text 9
  <div id="drawer" class="drawer-closed">
    <button>
      Button Inside Drawer!
    </button>
  </div>
</div>

about 4 years ago · Juan Pablo Isaza 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