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

0% Statements 0/11
0% Branches 0/10
0% Functions 0/1
0% Lines 0/10

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

     /*!
    * NOTE: pulled from react-modal - EP
    * https://github.com/reactjs/react-modal/blob/596f42330bf3ed63f975fd78c15227ab1bea717b/lib/helpers/scopeTab.js
    */

    import findTabbable from './tabbable';

    export default function scopeTab (node, event) {
      const tabbable = findTabbable(node);
      if (!tabbable.length) {
        event.preventDefault();
        return;
      }
      const finalTabbable = tabbable[event.shiftKey ? 0 : tabbable.length - 1];
      const leavingFinalTabbable = (
        finalTabbable === document.activeElement ||
        // handle immediate shift+tab after opening with mouse
        node === document.activeElement
      );
      if (!leavingFinalTabbable) return;
      event.preventDefault();
      const target = tabbable[event.shiftKey ? tabbable.length - 1 : 0];
      target.focus();
    }