UNPKG

tabbable

Version:

Returns an array of all tabbable DOM nodes within a containing node.

7 lines (6 loc) 2.95 kB
/*! * tabbable 5.2.0 * @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE */ var e=["input","select","textarea","a[href]","button","[tabindex]","audio[controls]","video[controls]",'[contenteditable]:not([contenteditable="false"])',"details>summary:first-of-type","details"],t=e.join(","),n="undefined"==typeof Element?function(){}:Element.prototype.matches||Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector,r=function(e,r,o){var i=Array.prototype.slice.apply(e.querySelectorAll(t));return r&&n.call(e,t)&&i.unshift(e),i=i.filter(o)},o=function(e){var t=parseInt(e.getAttribute("tabindex"),10);return isNaN(t)?function(e){return"true"===e.contentEditable}(e)?0:"AUDIO"!==e.nodeName&&"VIDEO"!==e.nodeName&&"DETAILS"!==e.nodeName||null!==e.getAttribute("tabindex")?e.tabIndex:0:t},i=function(e,t){return e.tabIndex===t.tabIndex?e.documentOrder-t.documentOrder:e.tabIndex-t.tabIndex},a=function(e){return"INPUT"===e.tagName},u=function(e){return function(e){return a(e)&&"radio"===e.type}(e)&&!function(e){if(!e.name)return!0;var t,n=e.form||e.ownerDocument,r=function(e){return n.querySelectorAll('input[type="radio"][name="'+e+'"]')};if("undefined"!=typeof window&&void 0!==window.CSS&&"function"==typeof window.CSS.escape)t=r(window.CSS.escape(e.name));else try{t=r(e.name)}catch(e){return console.error("Looks like you have a radio button with a name attribute containing invalid CSS selector characters and need the CSS.escape polyfill: %s",e.message),!1}var o=function(e,t){for(var n=0;n<e.length;n++)if(e[n].checked&&e[n].form===t)return e[n]}(t,e.form);return!o||o===e}(e)},c=function(e,t){return!(t.disabled||function(e){return a(e)&&"hidden"===e.type}(t)||function(e,t){if("hidden"===getComputedStyle(e).visibility)return!0;var r=n.call(e,"details>summary:first-of-type")?e.parentElement:e;if(n.call(r,"details:not([open]) *"))return!0;if(t&&"full"!==t){if("non-zero-area"===t){var o=e.getBoundingClientRect(),i=o.width,a=o.height;return 0===i&&0===a}}else for(;e;){if("none"===getComputedStyle(e).display)return!0;e=e.parentElement}return!1}(t,e.displayCheck)||function(e){return"DETAILS"===e.tagName&&Array.prototype.slice.apply(e.children).some((function(e){return"SUMMARY"===e.tagName}))}(t))},d=function(e,t){return!(!c(e,t)||u(t)||o(t)<0)},l=function(e,t){var n=[],a=[];return r(e,(t=t||{}).includeContainer,d.bind(null,t)).forEach((function(e,t){var r=o(e);0===r?n.push(e):a.push({documentOrder:t,tabIndex:r,node:e})})),a.sort(i).map((function(e){return e.node})).concat(n)},f=function(e,t){return r(e,(t=t||{}).includeContainer,c.bind(null,t))},p=function(e,r){if(r=r||{},!e)throw new Error("No node provided");return!1!==n.call(e,t)&&d(r,e)},s=e.concat("iframe").join(","),m=function(e,t){if(t=t||{},!e)throw new Error("No node provided");return!1!==n.call(e,s)&&c(t,e)};export{f as focusable,m as isFocusable,p as isTabbable,l as tabbable}; //# sourceMappingURL=index.esm.min.js.map