# All files / composer/__legacy-buffer-web-shared-components__/modal tabbable.js

0% Statements 0/19
0% Branches 0/20
0% Functions 0/6
0% Lines 0/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    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
    49
    50
    51
    52
    53

     /*!
     * 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/
     *
     * NOTE: pulled from react-modal - EP
     * https://github.com/reactjs/react-modal/blob/75a1aa360c25208b4f08648863cbaa8d737ef9fe/lib/helpers/tabbable.js
     */

     function hidden (el) {
       return (el.offsetWidth <= 0 && el.offsetHeight <= 0) ||
         el.style.display === 'none';
     }

     function visible (element) {
       let ourElement = element;
       while (ourElement) {
         if (ourElement === document.body) break;
         if (hidden(ourElement)) return false;
         ourElement = ourElement.parentNode;
       }
       return true;
     }

     function focusable (element, isTabIndexNotNaN) {
       const nodeName = element.nodeName.toLowerCase();
       const isFocusableLink = nodeName === 'a' ?
        element.href || isTabIndexNotNaN : isTabIndexNotNaN;
       return (/input|select|textarea|button|object/.test(nodeName) ?
        !element.disabled : isFocusableLink
        ) && 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);
     }

     function findTabbableDescendants (element) {
       return [].slice.call(element.querySelectorAll('*'), 0).filter(el => tabbable(el));
     }

     export default findTabbableDescendants;