feat: do not animate indicator when scrolling

This commit is contained in:
alistair3149 2022-10-23 18:06:52 -04:00
parent ce35fb8908
commit e124e8170a
No known key found for this signature in database
2 changed files with 17 additions and 11 deletions

View file

@ -118,12 +118,22 @@ function initTabber( tabber, count ) {
}
};
var updateIndicator = function () {
var updateIndicator = function ( showTransition ) {
var activeTab = tabList.querySelector( ACTIVETAB_SELECTOR );
var width = getActualSize( activeTab, 'width' );
indicator.style.width = width + 'px';
indicator.style.transform = 'translateX(' + ( activeTab.offsetLeft - tabList.scrollLeft ) + 'px)';
indicator.style.transition = '';
// Do not animate when user prefers reduced motion
if ( window.matchMedia( '(prefers-reduced-motion: reduce)' ).matches ) {
return;
}
if ( showTransition ) {
indicator.style.transition = 'transform 250ms ease, width 250ms ease';
}
};
var resizeObserver = null;
@ -201,8 +211,10 @@ function initTabber( tabber, count ) {
// Listen for scroll event on header
// Also triggered by side-scrolling using other means other than the buttons
tabList.addEventListener( 'scroll', function () {
window.requestAnimationFrame( function () {
updateButtons();
updateIndicator();
updateIndicator( false );
} );
} );
// Add class to enable animation
@ -300,7 +312,7 @@ function initTabber( tabber, count ) {
targetTab.setAttribute( 'aria-selected', true );
targetPanel.setAttribute( 'aria-hidden', false );
updateIndicator();
updateIndicator( true );
// Lazyload transclusion if needed
if ( allowRemoteLoad &&

View file

@ -246,12 +246,6 @@
&__header {
scroll-behavior: smooth;
}
&__indicator {
// Placeholder animation
// TODO: Allow indicator to sync with panel scrolling
transition: transform 250ms ease, width 250ms ease;
}
}
.tabber--animate {