Skip to content

Commit

Permalink
refactor(segment): update scrollActiveButtonIntoView
Browse files Browse the repository at this point in the history
  • Loading branch information
thetaPC committed Sep 19, 2024
1 parent 221bb42 commit f0ae0fa
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions core/src/components/segment/segment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ export class Segment implements ComponentInterface {
* scroll container.
*/
const centeredX = activeButtonLeft - scrollContainerBox.width / 2 + activeButtonBox.width / 2;
console.log(centeredX);

/**
* We intentionally use scrollBy here instead of scrollIntoView
Expand All @@ -354,10 +355,24 @@ export class Segment implements ComponentInterface {
* within the scroll container, the browser will attempt
* to center by as much as it can.
*/
el.scrollBy({
top: 0,
left: centeredX,
// el.scrollBy({
// top: 0,
// left: centeredX,
// behavior: smoothScroll ? 'smooth' : 'instant',
// });

activeButton.scrollIntoView({
behavior: smoothScroll ? 'smooth' : 'instant',
inline: 'center',

/**
* Segment should scroll on the
* horizontal axis. `block: 'nearest'`
* ensures that the vertical axis
* does not scroll if the segment
* as a whole is already in view.
*/
block: 'nearest',
});
}
}
Expand Down

0 comments on commit f0ae0fa

Please sign in to comment.