Skip to content

Commit 8053d64

Browse files
- use RTL helper;
1 parent 62ffe16 commit 8053d64

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { ComponentInterface, EventEmitter } from '@stencil/core';
22
import { Component, Element, Event, Host, Listen, Method, Prop, State, h } from '@stencil/core';
3+
import { isRTL } from '@utils/rtl';
34

45
import type { SegmentViewScrollEvent } from './segment-view-interface';
56

@@ -39,8 +40,9 @@ export class SegmentView implements ComponentInterface {
3940
@Listen('scroll')
4041
handleScroll(ev: Event) {
4142
const { scrollLeft, scrollWidth, clientWidth } = ev.target as HTMLElement;
42-
const isRTL = window.getComputedStyle(this.el).direction === 'rtl';
43-
const scrollRatio = (isRTL ? -1 : 1) * (scrollLeft / (scrollWidth - clientWidth));
43+
const max = scrollWidth - clientWidth;
44+
const scrollRatio = (isRTL(this.el) ? -1 : 1) * (scrollLeft / max);
45+
4446

4547
this.ionSegmentViewScroll.emit({
4648
scrollRatio,
@@ -119,17 +121,18 @@ export class SegmentView implements ComponentInterface {
119121
async setContent(id: string, smoothScroll = true) {
120122
const contents = this.getSegmentContents();
121123
const index = contents.findIndex((content) => content.id === id);
122-
const isRTL = window.getComputedStyle(this.el).direction === 'rtl';
123124

124125
if (index === -1) return;
125126

126127
this.isManualScroll = false;
127128
this.resetScrollEndTimeout();
128129

129130
const contentWidth = this.el.offsetWidth;
131+
const offset = index * contentWidth;
132+
130133
this.el.scrollTo({
131134
top: 0,
132-
left: (isRTL ? -1 : 1) * index * contentWidth,
135+
left: (isRTL(this.el) ? -1 : 1 ) * offset,
133136
behavior: smoothScroll ? 'smooth' : 'instant',
134137
});
135138
}

0 commit comments

Comments
 (0)