UNPKG

device-navigation

Version:

Navigate HTML elements in two dimensions with non-pointer devices.

32 lines (31 loc) 769 B
import { waitUntil } from '@augment-vir/assert'; import { isElementFocused } from '@augment-vir/web'; /** * Focuses an element. * * @category Util */ export function focusElement(element) { element.scrollIntoView({ behavior: 'smooth', inline: 'center', block: 'center' }); element.focus(); } /** * Waits until an element is focused. * * @category Util */ export async function waitUntilFocused(element, message) { await waitUntil.isTrue(() => { return isElementFocused(element); }, {}, message); } /** * Waits until an element is blurred (unfocused). * * @category Util */ export async function waitUntilBlurred(element, message) { await waitUntil.isTrue(() => { return !isElementFocused(element); }, {}, message); }