@@ -28,6 +28,7 @@ export class Segment implements ComponentInterface {
2828 private valueBeforeGesture ?: SegmentValue ;
2929
3030 private segmentViewEl ?: HTMLIonSegmentViewElement | null = null ;
31+ private scrolledIndicator ?: HTMLDivElement | null = null ;
3132
3233 @Element ( ) el ! : HTMLIonSegmentElement ;
3334
@@ -87,7 +88,11 @@ export class Segment implements ComponentInterface {
8788 const current = buttons . find ( ( button ) => button . value === value ) ;
8889
8990 if ( previous && current ) {
90- this . checkButton ( previous , current ) ;
91+ if ( ! this . segmentViewEl ) {
92+ this . checkButton ( previous , current ) ;
93+ } else {
94+ this . setCheckedClasses ( ) ;
95+ }
9196 }
9297 }
9398
@@ -96,7 +101,11 @@ export class Segment implements ComponentInterface {
96101 * Used by `ion-segment-button` to determine if the button should be checked.
97102 */
98103 this . ionSelect . emit ( { value } ) ;
99- this . scrollActiveButtonIntoView ( ) ;
104+
105+ // The scroll listener should handle scrolling the active button into view as needed
106+ if ( ! this . segmentViewEl ) {
107+ this . scrollActiveButtonIntoView ( ) ;
108+ }
100109 }
101110
102111 /**
@@ -357,10 +366,13 @@ export class Segment implements ComponentInterface {
357366 const index = buttons . findIndex ( ( button ) => button . value === this . value ) ;
358367 const current = buttons [ index ] ;
359368 const indicatorEl = this . getIndicator ( current ) ;
369+ this . scrolledIndicator = indicatorEl ;
370+
371+ const { scrollDirection, scrollDistancePercentage, scrollDistance } = ev . detail ;
360372
361- const { scrollDirection , scrollDistancePercentage } = ev . detail ;
373+ console . log ( 'scroll' , scrollDistancePercentage , scrollDistance ) ;
362374
363- if ( indicatorEl ) {
375+ if ( indicatorEl && ! isNaN ( scrollDistancePercentage ) ) {
364376 indicatorEl . style . transition = 'transform 0.3s ease-out' ;
365377
366378 const scrollDistance = scrollDistancePercentage * current . getBoundingClientRect ( ) . width ;
@@ -390,6 +402,19 @@ export class Segment implements ComponentInterface {
390402 }
391403 }
392404
405+ @Listen ( 'ionSegmentViewScrollStart' , { target : 'body' } )
406+ onScrollStart ( ) { }
407+
408+ @Listen ( 'ionSegmentViewScrollEnd' , { target : 'body' } )
409+ onScrollEnd ( ev : CustomEvent < { activeContentId : string } > ) {
410+ this . value = ev . detail . activeContentId ;
411+
412+ if ( this . scrolledIndicator ) {
413+ this . scrolledIndicator . style . transition = '' ;
414+ this . scrolledIndicator . style . transform = '' ;
415+ }
416+ }
417+
393418 /**
394419 * Finds the related segment view and sets its current content
395420 * based on the selected segment button. This method
0 commit comments