( hostToFocus: HTMLElement | null | undefined, fallbackElement: T )
| 66 | * the host element itself. |
| 67 | */ |
| 68 | const focusElementInContext = <T extends HTMLElement>( |
| 69 | hostToFocus: HTMLElement | null | undefined, |
| 70 | fallbackElement: T |
| 71 | ) => { |
| 72 | let elementToFocus = hostToFocus; |
| 73 | |
| 74 | const shadowRoot = hostToFocus?.shadowRoot; |
| 75 | if (shadowRoot) { |
| 76 | // If there are no inner focusable elements, just focus the host element. |
| 77 | elementToFocus = shadowRoot.querySelector<HTMLElement>(focusableQueryString) || hostToFocus; |
| 78 | } |
| 79 | |
| 80 | if (elementToFocus) { |
| 81 | const radioGroup = elementToFocus.closest('ion-radio-group'); |
| 82 | |
| 83 | if (radioGroup) { |
| 84 | radioGroup.setFocus(); |
| 85 | } else { |
| 86 | focusVisibleElement(elementToFocus); |
| 87 | } |
| 88 | } else { |
| 89 | // Focus fallback element instead of letting focus escape |
| 90 | fallbackElement.focus(); |
| 91 | } |
| 92 | }; |
no test coverage detected