Skip to content

Commit 1079566

Browse files
- calculate scroll having into consideration dir value;
1 parent c339bc3 commit 1079566

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

core/src/components/segment-view/segment-view.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ export class SegmentView implements ComponentInterface {
3939
@Listen('scroll')
4040
handleScroll(ev: Event) {
4141
const { scrollLeft, scrollWidth, clientWidth } = ev.target as HTMLElement;
42-
const scrollRatio = scrollLeft / (scrollWidth - clientWidth);
42+
const isRTL = window.getComputedStyle(this.el).direction === 'rtl';
43+
const scrollRatio = (isRTL ? -1 : 1) * scrollLeft / (scrollWidth - clientWidth);
4344

4445
this.ionSegmentViewScroll.emit({
4546
scrollRatio,
@@ -118,6 +119,7 @@ export class SegmentView implements ComponentInterface {
118119
async setContent(id: string, smoothScroll = true) {
119120
const contents = this.getSegmentContents();
120121
const index = contents.findIndex((content) => content.id === id);
122+
const isRTL = window.getComputedStyle(this.el).direction === 'rtl';
121123

122124
if (index === -1) return;
123125

@@ -127,7 +129,7 @@ export class SegmentView implements ComponentInterface {
127129
const contentWidth = this.el.offsetWidth;
128130
this.el.scrollTo({
129131
top: 0,
130-
left: index * contentWidth,
132+
left: (isRTL ? -1 : 1) * index * contentWidth,
131133
behavior: smoothScroll ? 'smooth' : 'instant',
132134
});
133135
}

0 commit comments

Comments
 (0)