Skip to content

Commit ae2704f

Browse files
author
Tanner Reits
committed
fix(segment): only handle events for correct instance
1 parent 16c728b commit ae2704f

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

core/src/components/segment/segment.tsx

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -406,20 +406,32 @@ export class Segment implements ComponentInterface {
406406
}
407407

408408
@Listen('ionSegmentViewScrollStart', { target: 'body' })
409-
onScrollStart() {
410-
this.isScrolling = true;
409+
onScrollStart(ev: CustomEvent) {
410+
const dispatchedFrom = ev.target as HTMLElement;
411+
const segmentViewEl = this.segmentViewEl as EventTarget;
412+
const segmentEl = this.el;
413+
414+
if (ev.composedPath().includes(segmentViewEl) || dispatchedFrom?.contains(segmentEl)) {
415+
this.isScrolling = true;
416+
}
411417
}
412418

413419
@Listen('ionSegmentViewScrollEnd', { target: 'body' })
414420
onScrollEnd(ev: CustomEvent<{ activeContentId: string }>) {
415-
this.value = ev.detail.activeContentId;
421+
const dispatchedFrom = ev.target as HTMLElement;
422+
const segmentViewEl = this.segmentViewEl as EventTarget;
423+
const segmentEl = this.el;
416424

417-
if (this.scrolledIndicator) {
418-
this.scrolledIndicator.style.transition = '';
419-
this.scrolledIndicator.style.transform = '';
420-
}
425+
if (ev.composedPath().includes(segmentViewEl) || dispatchedFrom?.contains(segmentEl)) {
426+
this.value = ev.detail.activeContentId;
421427

422-
this.isScrolling = false;
428+
if (this.scrolledIndicator) {
429+
this.scrolledIndicator.style.transition = '';
430+
this.scrolledIndicator.style.transform = '';
431+
}
432+
433+
this.isScrolling = false;
434+
}
423435
}
424436

425437
/**

0 commit comments

Comments
 (0)