Skip to content

bug: ion-select with action-sheet interface and header focuses the previous item of the selected option #30480

Open
@crazyserver

Description

@crazyserver

Prerequisites

Ionic Framework Version

v8.x

Current Behavior

With the following ion-select:

<ion-select
  aria-label="Fruit"
  interface="action-sheet"
  value="oranges"
  placeholder="Select fruit"
  [interfaceOptions]="{ header: 'Header' }"
>
  <ion-select-option value="apples">Apples</ion-select-option>
  <ion-select-option value="oranges">Oranges</ion-select-option>
  <ion-select-option value="bananas">Bananas</ion-select-option>
</ion-select>

When the action sheet is opened, the focused element with "ion-focused" class is the previous of the one that is selected.
On the code it searches the index of the selected item but then it uses nth-child to select it that takes into account the header of the action sheet.

A workaround is to remove the header.

Expected Behavior

The selected element is the one focused.

Steps to Reproduce

  1. Click on the select to open it
  2. See that "Apples" is highlighted instead of "Oranges"

Code Reproduction URL

https://stackblitz.com/edit/f6jtmmrf

Ionic Info

Ionic:

Ionic CLI : 7.2.1 (/Users/pau/.nvm/versions/node/v20.18.1/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/angular 8.5.0
@angular-devkit/build-angular : 17.3.13
@angular-devkit/schematics : 17.3.13
@angular/cli : 17.3.13
@ionic/angular-toolkit : 11.0.1

Cordova:

Cordova CLI : 12.0.0 (cordova-lib@12.0.2)
Cordova Platforms : android 14.0.0, ios 7.1.1
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, (and 16 other plugins)

Utility:

cordova-res : not installed globally
native-run : 2.0.1

System:

ios-sim : 8.0.2
NodeJS : v20.18.1 (/Users/pau/.nvm/versions/node/v20.18.1/bin/node)
npm : 10.8.2
OS : macOS Unknown
Xcode : Xcode 16.4 Build version 16F6

But I've tested in ionic 8.6.1 also.

Additional Information

No response

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