@@ -344,21 +344,35 @@ export class Segment implements ComponentInterface {
344344 const centeredX = activeButtonLeft - scrollContainerBox . width / 2 + activeButtonBox . width / 2 ;
345345
346346 /**
347- * We intentionally use scrollBy here instead of scrollIntoView
347+ * newScrollPosition is the absolute scroll position that the
348+ * container needs to move to in order to center the active button.
349+ * It is calculated by adding the current scroll position
350+ * (scrollLeft) to the offset needed to center the button
351+ * (centeredX).
352+ */
353+ const newScrollPosition = el . scrollLeft + centeredX ;
354+
355+ /**
356+ * We intentionally use scrollTo here instead of scrollIntoView
348357 * to avoid a WebKit bug where accelerated animations break
349358 * when using scrollIntoView. Using scrollIntoView will cause the
350359 * segment container to jump during the transition and then snap into place.
351360 * This is because scrollIntoView can potentially cause parent element
352- * containers to also scroll. scrollBy does not have this same behavior, so
361+ * containers to also scroll. scrollTo does not have this same behavior, so
353362 * we use this API instead.
354363 *
364+ * scrollTo is used instead of scrollBy because there is a
365+ * Webkit bug that causes scrollBy to not work smoothly when
366+ * the active button is near the edge of the scroll container.
367+ * This leads to the buttons to jump around during the transition.
368+ *
355369 * Note that if there is not enough scrolling space to center the element
356370 * within the scroll container, the browser will attempt
357371 * to center by as much as it can.
358372 */
359- el . scrollBy ( {
373+ el . scrollTo ( {
360374 top : 0 ,
361- left : centeredX ,
375+ left : newScrollPosition ,
362376 behavior : smoothScroll ? 'smooth' : 'instant' ,
363377 } ) ;
364378 }
0 commit comments