UNPKG

react-native-web-headroom

Version:
58 lines (49 loc) 1.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = findTabbableDescendants; /*! * 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/ */ var tabbableNode = /input|select|textarea|button|object/; function hidesContents(element) { var zeroSize = element.offsetWidth <= 0 && element.offsetHeight <= 0; // If the node is empty, this is good enough if (zeroSize && !element.innerHTML) return true; // Otherwise we need to check some styles var style = window.getComputedStyle(element); return zeroSize ? style.getPropertyValue("overflow") !== "visible" : style.getPropertyValue("display") == "none"; } function visible(element) { var parentElement = element; while (parentElement) { if (parentElement === document.body) break; if (hidesContents(parentElement)) return false; parentElement = parentElement.parentNode; } return true; } function focusable(element, isTabIndexNotNaN) { var nodeName = element.nodeName.toLowerCase(); var res = tabbableNode.test(nodeName) && !element.disabled || (nodeName === "a" ? element.href || isTabIndexNotNaN : isTabIndexNotNaN); return res && 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(tabbable); } module.exports = exports["default"];