UNPKG

@public-ui/components

Version:

Contains all web components that belong to KoliBri - The accessible HTML-Standard.

35 lines (34 loc) 1.08 kB
/*! * KoliBri - The accessible HTML-Standard */ import { waitForThemed } from "./element-themed"; const MAX_FOCUS_ATTEMPTS = 10; export async function delegateFocus(host, callback) { try { if (!host.hasAttribute('data-themed')) { await waitForThemed(host); } await callback(); } catch (_a) { throw new Error(`The interactive element inside the KoliBri web component could not be focused. Try calling the focus method on the web component after a short delay again.`); } } function isActiveElement(element) { const root = element.getRootNode(); if (root instanceof ShadowRoot) { return root.activeElement === element; } return document.activeElement === element; } export async function setFocus(element) { let attempts = 0; do { if (element) { element.focus(); } await new Promise((r) => requestAnimationFrame(r)); attempts++; } while (!isActiveElement(element) && attempts < MAX_FOCUS_ATTEMPTS); } //# sourceMappingURL=element-focus.js.map