You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
564 B

2 months ago
  1. // @flow
  2. import getParentNode from './getParentNode';
  3. import isScrollParent from './isScrollParent';
  4. import getNodeName from './getNodeName';
  5. import { isHTMLElement } from './instanceOf';
  6. export default function getScrollParent(node: Node): HTMLElement {
  7. if (['html', 'body', '#document'].indexOf(getNodeName(node)) >= 0) {
  8. // $FlowFixMe[incompatible-return]: assume body is always available
  9. return node.ownerDocument.body;
  10. }
  11. if (isHTMLElement(node) && isScrollParent(node)) {
  12. return node;
  13. }
  14. return getScrollParent(getParentNode(node));
  15. }