From 44e837479154546b089e584f8308bae43995dec2 Mon Sep 17 00:00:00 2001 From: Brandy Carney Date: Mon, 23 Sep 2024 14:29:03 -0400 Subject: [PATCH] fix(segment): only call updateSegmentView when gesture ends or button is clicked --- core/src/components/segment/segment.tsx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/core/src/components/segment/segment.tsx b/core/src/components/segment/segment.tsx index 0b65626733..f991ef18ba 100644 --- a/core/src/components/segment/segment.tsx +++ b/core/src/components/segment/segment.tsx @@ -202,6 +202,7 @@ export class Segment implements ComponentInterface { if (value !== undefined) { if (this.valueBeforeGesture !== value) { this.emitValueChange(); + this.updateSegmentView(); } } this.valueBeforeGesture = undefined; @@ -234,11 +235,7 @@ export class Segment implements ComponentInterface { const buttons = this.getButtons(); buttons.forEach((button) => { - if (activated) { - button.classList.add('segment-button-activated'); - } else { - button.classList.remove('segment-button-activated'); - } + button.classList.toggle('segment-button-activated', activated); }); this.activated = activated; } @@ -307,7 +304,6 @@ export class Segment implements ComponentInterface { this.value = current.value; this.setCheckedClasses(); - this.updateSegmentView(); } private setCheckedClasses() { @@ -323,6 +319,13 @@ export class Segment implements ComponentInterface { } } + /** + * Finds the related segment view and sets its current content + * based on the selected segment button. This method + * should be called only after the gesture is completed + * (if dragging between segments) or when a segment button + * is clicked directly. + */ private updateSegmentView() { const buttons = this.getButtons(); const button = buttons.find((btn) => btn.value === this.value); @@ -505,6 +508,7 @@ export class Segment implements ComponentInterface { if (current !== previous) { this.emitValueChange(); + this.updateSegmentView(); } if (this.scrollable || !this.swipeGesture) {