UNPKG

843 BPlain TextView Raw
1const focusableElements = [
2 'input:not([disabled]):not([type=hidden])',
3 'select:not([disabled])',
4 'textarea:not([disabled])',
5 'button:not([disabled])',
6 'a[href]',
7 'area[href]',
8 'summary',
9 'iframe',
10 'object',
11 'embed',
12 'audio[controls]',
13 'video[controls]',
14 '[contenteditable]:not([contenteditable^="false"])'
15];
16
17const FOCUSABLE_ELEMENT_SELECTOR = focusableElements.join(':not([hidden]),') + ',[tabindex]:not([disabled]):not([hidden])';
18
19focusableElements.push('[tabindex]:not([tabindex="-1"]):not([disabled])');
20const TABBABLE_ELEMENT_SELECTOR = focusableElements.join(':not([hidden]):not([tabindex="-1"]),');
21
22export function isFocusable(element: Element) {
23 return element.matches(FOCUSABLE_ELEMENT_SELECTOR);
24}
25
26export function isTabbable(element: Element) {
27 return element.matches(TABBABLE_ELEMENT_SELECTOR);
28}