MCPcopy Index your code
hub / github.com/ionic-team/ionic-framework / focusElementInOverlay

Function focusElementInOverlay

core/src/utils/overlays.ts:162–177  ·  view source on GitHub ↗
(hostToFocus: HTMLElement | null | undefined, overlay: HTMLIonOverlayElement)

Source from the content-addressed store, hash-verified

160 * the host element itself.
161 */
162const focusElementInOverlay = (hostToFocus: HTMLElement | null | undefined, overlay: HTMLIonOverlayElement) => {
163 let elementToFocus = hostToFocus;
164
165 const shadowRoot = hostToFocus?.shadowRoot;
166 if (shadowRoot) {
167 // If there are no inner focusable elements, just focus the host element.
168 elementToFocus = shadowRoot.querySelector<HTMLElement>(focusableQueryString) || hostToFocus;
169 }
170
171 if (elementToFocus) {
172 focusVisibleElement(elementToFocus);
173 } else {
174 // Focus overlay instead of letting focus escape
175 overlay.focus();
176 }
177};
178
179/**
180 * Traps keyboard focus inside of overlay components.

Callers 2

trapScopedFocusFunction · 0.85
trapShadowFocusFunction · 0.85

Calls 1

focusVisibleElementFunction · 0.90

Tested by

no test coverage detected