forked from reactjs/react-modal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtabbable.js
More file actions
48 lines (42 loc) · 1.31 KB
/
Copy pathtabbable.js
File metadata and controls
48 lines (42 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*!
* Adapted from jQuery UI core
*
* http://jqueryui.com
*
* Copyright 2014 jQuery Foundation and other contributors
* Released under the MIT license.
* http://jquery.org/license
*
* http://api.jqueryui.com/category/ui-core/
*/
const tabbableNode = /input|select|textarea|button|object/;
function hidden(el) {
return (el.offsetWidth <= 0 && el.offsetHeight <= 0) ||
el.style.display === 'none';
}
function visible(element) {
let parentElement = element;
while (parentElement) {
if (parentElement === document.body) break;
if (hidden(parentElement)) return false;
parentElement = parentElement.parentNode;
}
return true;
}
function focusable(element, isTabIndexNotNaN) {
const nodeName = element.nodeName.toLowerCase();
const res = ((tabbableNode.test(nodeName)) && !element.disabled) ||
(nodeName === "a" ? element.href || isTabIndexNotNaN : isTabIndexNotNaN);
return res && visible(element);
}
function tabbable(element) {
let tabIndex = element.getAttribute('tabindex');
if (tabIndex === null) tabIndex = undefined;
const isTabIndexNaN = isNaN(tabIndex);
return (isTabIndexNaN || tabIndex >= 0) && focusable(element, !isTabIndexNaN);
}
export default function findTabbableDescendants(element) {
return [].slice.call(
element.querySelectorAll('*'), 0
).filter(tabbable);
}