UtilOptional

getFocusableElements

Lists the focusable descendants of an element, in DOM order.

Usage

import { getFocusableElements } from 'ngwr/utils';

const els = getFocusableElements(menuRef.nativeElement);
els[0]?.focus();

API

NameDescriptionTypeDefault
getFocusableElements(root)Every focusable descendant of root, in DOM order. Skips disabled and tabindex="-1" elements, and unrendered ones unless they hold focus. A positive tabindex is not sorted.(root: HTMLElement) => readonly HTMLElement[]—

See also