Skip to content

Commit 89d8e90

Browse files
author
Tanner Reits
committed
fix(segment): scroll segment button into view if appropriate
1 parent ae2704f commit 89d8e90

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

core/src/components/segment/segment.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,23 @@ export class Segment implements ComponentInterface {
401401
// Apply the clamped transform value to the indicator element
402402
const transform = `translate3d(${clampedTransform}px, 0, 0)`;
403403
indicatorEl.style.setProperty('transform', transform);
404+
405+
// Scroll the buttons if the indicator is out of view
406+
const indicatorX = indicatorEl.getBoundingClientRect().x;
407+
const buttonWidth = current.getBoundingClientRect().width;
408+
if (evScrollDistance < 0 && indicatorX < 0) {
409+
this.el.scrollBy({
410+
top: 0,
411+
left: indicatorX,
412+
behavior: 'instant',
413+
});
414+
} else if (evScrollDistance > 0 && indicatorX + buttonWidth > this.el.offsetWidth) {
415+
this.el.scrollBy({
416+
top: 0,
417+
left: indicatorX + buttonWidth - this.el.offsetWidth,
418+
behavior: 'instant',
419+
});
420+
}
404421
}
405422
}
406423
}

0 commit comments

Comments
 (0)