fix(select): focus the correct selected item in an action sheet interface with a header (#30481)

Issue number: resolves #30480

---------

## What is the current behavior?
When using a select component with the `action-sheet` interface, a
`header`, and a default selected value, the action sheet opens with the
wrong item focused. This happens because the focus logic uses
`nth-child` to target the selected item, which incorrectly includes the
header since it is a child element. As a result, the focus is shifted
one item above the correct selection.

## What is the new behavior?
- Correctly focus the selected item when opening an `action-sheet` with
a header from a select.
- Adds e2e tests for verifying this behavior.

## Does this introduce a breaking change?

- [ ] Yes
- [X] No

## Other information


[Preview](https://ionic-framework-git-fork-crazyserver-patch-2-ionic1.vercel.app/src/components/select/test/basic)

---------

Co-authored-by: Brandy Smith <6577830+brandyscarney@users.noreply.github.com>
This commit is contained in:
Pau Ferrer Ocaña
2025-07-01 19:11:00 +02:00
committed by GitHub
parent 7b9f306d1f
commit 80a111cffa
2 changed files with 225 additions and 1 deletions

View File

@@ -349,7 +349,7 @@ export class Select implements ComponentInterface {
const indexOfSelected = this.childOpts.findIndex((o) => o.value === this.value);
if (indexOfSelected > -1) {
const selectedItem = overlay.querySelector<HTMLElement>(
`.select-interface-option:nth-child(${indexOfSelected + 1})`
`.select-interface-option:nth-of-type(${indexOfSelected + 1})`
);
if (selectedItem) {