1 | const 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 |
|
17 | const FOCUSABLE_ELEMENT_SELECTOR = focusableElements.join(':not([hidden]),') + ',[tabindex]:not([disabled]):not([hidden])';
|
18 |
|
19 | focusableElements.push('[tabindex]:not([tabindex="-1"]):not([disabled])');
|
20 | const TABBABLE_ELEMENT_SELECTOR = focusableElements.join(':not([hidden]):not([tabindex="-1"]),');
|
21 |
|
22 | export function isFocusable(element: Element) {
|
23 | return element.matches(FOCUSABLE_ELEMENT_SELECTOR);
|
24 | }
|
25 |
|
26 | export function isTabbable(element: Element) {
|
27 | return element.matches(TABBABLE_ELEMENT_SELECTOR);
|
28 | }
|