all files / src/utils/ scrollParent.js

85.71% Statements 18/21
64.29% Branches 9/14
100% Functions 1/1
85.71% Lines 18/21
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                49×       49× 49× 49×   49× 245× 37×     208× 208× 208× 208× 208×   208×       208× 12×     196×          
'use strict';
 
Object.defineProperty(exports, "__esModule", {
  value: true
});
/**
 * @fileOverview Find scroll parent
 */
 
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;
};