fix(segment): only handle events for correct instance

This commit is contained in:
Tanner Reits
2024-09-28 20:33:48 -04:00
parent 16c728b040
commit ae2704fdc8

View File

@@ -406,20 +406,32 @@ export class Segment implements ComponentInterface {
}
@Listen('ionSegmentViewScrollStart', { target: 'body' })
onScrollStart() {
this.isScrolling = true;
onScrollStart(ev: CustomEvent) {
const dispatchedFrom = ev.target as HTMLElement;
const segmentViewEl = this.segmentViewEl as EventTarget;
const segmentEl = this.el;
if (ev.composedPath().includes(segmentViewEl) || dispatchedFrom?.contains(segmentEl)) {
this.isScrolling = true;
}
}
@Listen('ionSegmentViewScrollEnd', { target: 'body' })
onScrollEnd(ev: CustomEvent<{ activeContentId: string }>) {
this.value = ev.detail.activeContentId;
const dispatchedFrom = ev.target as HTMLElement;
const segmentViewEl = this.segmentViewEl as EventTarget;
const segmentEl = this.el;
if (this.scrolledIndicator) {
this.scrolledIndicator.style.transition = '';
this.scrolledIndicator.style.transform = '';
if (ev.composedPath().includes(segmentViewEl) || dispatchedFrom?.contains(segmentEl)) {
this.value = ev.detail.activeContentId;
if (this.scrolledIndicator) {
this.scrolledIndicator.style.transition = '';
this.scrolledIndicator.style.transform = '';
}
this.isScrolling = false;
}
this.isScrolling = false;
}
/**