Skip to content

bug: ion-segment does not automatically slide to the active ion-segment-button #28096

Description

@DiogoParrinha

Prerequisites

Ionic Framework Version

v7.x

Current Behavior

I have an ion-segment with multiple ion-segment-button entries, that go beyond the view.

When the view is loaded, the right button is selected but it may be beyond what's visible, and it doesn't automatically slide into the selected slide: (you can see a tiny green selection on the right side)
image

If I click the button, it slides to make it centered:
image

It seems the issue is really just the initialization.

Expected Behavior

The ion-segment-button should be as centered as possible, just like when we click them.

Steps to Reproduce

Create the following ion-segment:

  <ion-segment [scrollable]="true" value="6">
    <ion-segment-button value="1">
      <div class="day-container" class="ion-padding-top">
        <div class="day-of-week">Abc</div>
        <div class="day-of-month">13</div>
        <div class="month">Sep</div>
      </div>
    </ion-segment-button>
    <ion-segment-button value="2">
      <div class="day-container" class="ion-padding-top">
        <div class="day-of-week">Abc</div>
        <div class="day-of-month">13</div>
        <div class="month">Sep</div>
      </div>
    </ion-segment-button>
    <ion-segment-button value="3">
      <div class="day-container" class="ion-padding-top">
        <div class="day-of-week">Abc</div>
        <div class="day-of-month">13</div>
        <div class="month">Sep</div>
      </div>
    </ion-segment-button>
    <ion-segment-button value="4">
      <div class="day-container" class="ion-padding-top">
        <div class="day-of-week">Abc</div>
        <div class="day-of-month">13</div>
        <div class="month">Sep</div>
      </div>
    </ion-segment-button>
    <ion-segment-button value="5">
      <div class="day-container" class="ion-padding-top">
        <div class="day-of-week">Abc</div>
        <div class="day-of-month">13</div>
        <div class="month">Sep</div>
      </div>
    </ion-segment-button>
    <ion-segment-button value="6">
      <div class="day-container" class="ion-padding-top">
        <div class="day-of-week">Abc</div>
        <div class="day-of-month">13</div>
        <div class="month">Sep</div>
      </div>
    </ion-segment-button>
    <ion-segment-button value="7">
      <div class="day-container" class="ion-padding-top">
        <div class="day-of-week">Abc</div>
        <div class="day-of-month">13</div>
        <div class="month">Sep</div>
      </div>
    </ion-segment-button>
  </ion-segment>

The button 6 will be outside the view and it won't slide into it.

Code Reproduction URL

No response

Ionic Info

Ionic:

   Ionic CLI                     : 7.1.1 (...)
   Ionic Framework               : @ionic/angular 7.3.0
   @angular-devkit/build-angular : 14.2.12
   @angular-devkit/schematics    : 14.2.12
   @angular/cli                  : 14.2.12
   @ionic/angular-toolkit        : not installed

Capacitor:

   Capacitor CLI      : 5.0.4
   @capacitor/android : 5.0.4
   @capacitor/core    : 5.0.4
   @capacitor/ios     : 5.0.4

Cordova:

   Cordova CLI       : not installed
   Cordova Platforms : not available
   Cordova Plugins   : not available

Utility:

   cordova-res : 0.15.3
   native-run  : 1.7.2

System:

   NodeJS : v18.16.1 (...)
   npm    : 9.8.1
   OS     : Windows 10```

### Additional Information

Disregard the other experiments outside the red boxes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions