mmdevcodes / a11y-slider

Library for simple and accessible sliders
https://a11yslider.js.org/
MIT License
53 stars 7 forks source link

Next/Prev buttons lead to jumpy behaviour in firefox when using display:grid #42

Open katomat opened 1 year ago

katomat commented 1 year ago

While testing a11y-slider we ran into a bug with Firefox and navigating with the prev/next buttons. When pressing one of the button quickly the slide would first animate the change to the correct slide and then jump back to an earlier one.

Steps to reproduce:

While we were able circumvent the bug by overriding the position:relative added by the a11y-slider container, there were multiple things that looked strange and perhaps are involved in causing the problem:

  1. _goPrevOrNext() calculates the slide to navigate to based on the current scroll position (via _getActiveAndVisible()). When clicking on a button while the animation is still ongoing the resulting target slide might be wrong.
  2. scrollToSlide() calls _setCSS(targetSlide) asynchronously which seems odd because by the time it is invoked the targetSlide might not actually be the position the user navigated to. The comment or the commit history are not clear of why this call is even needed. Deleting the entire setTimeout() block had no effect in our tests, which means it also didn’t fix the bug.

Some more observations that make things hard to debug (and might be the cause of yet unknown issues) are: