UNPKG

469 BJavaScriptView Raw
1/* @flow */
2const selector = 'input, a, textarea, select, button, [tabIndex]:not([tabIndex="-1"])';
3
4export function getFocusBounds(element: HTMLElement): Array<?HTMLElement> {
5 const focusableChildren = element.querySelectorAll(selector);
6 return [focusableChildren[0] || null, focusableChildren[focusableChildren.length - 1] || null];
7}
8
9export function getFirstFocusableChild(element: HTMLElement): ?HTMLElement {
10 return element.querySelector(selector);
11}