all files / src/utils/ scrollParent.js

86.36% Statements 19/22
64.29% Branches 9/14
100% Functions 1/1
86.36% Lines 19/22
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              47×       47× 47× 47×   47× 233× 35×     198× 198× 198× 198× 198×   198×       198× 12×     186×            
/**
 * @fileOverview Find scroll parent
 */
 
'use strict';
 
exports.__esModule = true;
 
exports['default'] = function (node) {
  Iif (!node) {
    return document;
  }
 
  var excludeStaticParent = node.style.position === 'absolute';
  var overflowRegex = /(scroll|auto)/;
  var parent = node;
 
  while (parent) {
    if (!parent.parentNode) {
      return node.ownerDocument || document;
    }
 
    var style = window.getComputedStyle(parent);
    var position = style.position;
    var overflow = style.overflow;
    var overflowX = style['overflow-x'];
    var overflowY = style['overflow-y'];
 
    Iif (position === 'static' && excludeStaticParent) {
      continue;
    }
 
    if (overflowRegex.test(overflow + overflowX + overflowY)) {
      return parent;
    }
 
    parent = parent.parentNode;
  }
 
  return node.ownerDocument || document;
};
 
module.exports = exports['default'];