(event?: UIEvent)
| 396 | */ |
| 397 | @Method() |
| 398 | async open(event?: UIEvent): Promise<any> { |
| 399 | if (this.disabled || this.isExpanded) { |
| 400 | return undefined; |
| 401 | } |
| 402 | this.isExpanded = true; |
| 403 | const overlay = (this.overlay = await this.createOverlay(event)); |
| 404 | |
| 405 | // Add logic to scroll selected item into view before presenting |
| 406 | const scrollSelectedIntoView = () => { |
| 407 | const indexOfSelected = this.childOpts.findIndex((o) => o.value === this.value); |
| 408 | if (indexOfSelected > -1) { |
| 409 | const selectedItem = overlay.querySelector<HTMLElement>( |
| 410 | `.select-interface-option:nth-of-type(${indexOfSelected + 1})` |
| 411 | ); |
| 412 | |
| 413 | if (selectedItem) { |
| 414 | /** |
| 415 | * Browsers such as Firefox do not |
| 416 | * correctly delegate focus when manually |
| 417 | * focusing an element with delegatesFocus. |
| 418 | * We work around this by manually focusing |
| 419 | * the interactive element. |
| 420 | * ion-radio and ion-checkbox are the only |
| 421 | * elements that ion-select-popover uses, so |
| 422 | * we only need to worry about those two components |
| 423 | * when focusing. |
| 424 | */ |
| 425 | const interactiveEl = selectedItem.querySelector<HTMLElement>('ion-radio, ion-checkbox') as |
| 426 | | HTMLIonRadioElement |
| 427 | | HTMLIonCheckboxElement |
| 428 | | null; |
| 429 | if (interactiveEl) { |
| 430 | selectedItem.scrollIntoView({ block: 'nearest' }); |
| 431 | // Needs to be called before `focusVisibleElement` to prevent issue with focus event bubbling |
| 432 | // and removing `ion-focused` style |
| 433 | interactiveEl.setFocus(); |
| 434 | } |
| 435 | |
| 436 | focusVisibleElement(selectedItem); |
| 437 | } |
| 438 | } else { |
| 439 | /** |
| 440 | * If no value is set then focus the first enabled option. |
| 441 | */ |
| 442 | const firstEnabledOption = overlay.querySelector<HTMLElement>( |
| 443 | 'ion-radio:not(.radio-disabled), ion-checkbox:not(.checkbox-disabled)' |
| 444 | ) as HTMLIonRadioElement | HTMLIonCheckboxElement | null; |
| 445 | |
| 446 | if (firstEnabledOption) { |
| 447 | /** |
| 448 | * Focus the option for the same reason as we do above. |
| 449 | * |
| 450 | * Needs to be called before `focusVisibleElement` to prevent issue with focus event bubbling |
| 451 | * and removing `ion-focused` style |
| 452 | */ |
| 453 | firstEnabledOption.setFocus(); |
| 454 | |
| 455 | focusVisibleElement(firstEnabledOption.closest('ion-item')!); |
no test coverage detected