react-tray
Version:
An accessible tray component useful for navigation menus
52 lines (45 loc) • 1.41 kB
JavaScript
/*!
* 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/
*/
;
Object.defineProperty(exports, '__esModule', {
value: true
});
function hidden(el) {
return el.offsetWidth <= 0 && el.offsetHeight <= 0 || el.style.display === 'none';
}
function visible(element) {
var el = element;
while (el) {
if (el === document.body) break;
if (hidden(el)) return false;
el = el.parentNode;
}
return true;
}
function focusable(element, isTabIndexNotNaN) {
var nodeName = element.nodeName.toLowerCase();
/* eslint no-nested-ternary:0 */
return (/input|select|textarea|button|object/.test(nodeName) ? !element.disabled : nodeName === 'a' ? element.href || isTabIndexNotNaN : isTabIndexNotNaN) && visible(element);
}
function tabbable(element) {
var tabIndex = element.getAttribute('tabindex');
if (tabIndex === null) tabIndex = undefined;
var isTabIndexNaN = isNaN(tabIndex);
return (isTabIndexNaN || tabIndex >= 0) && focusable(element, !isTabIndexNaN);
}
function findTabbableDescendants(element) {
return [].slice.call(element.querySelectorAll('*'), 0).filter(function (el) {
return tabbable(el);
});
}
exports['default'] = findTabbableDescendants;
module.exports = exports['default'];