UNPKG

@patternfly/react-core

Version:

This library provides a set of common React components for use with the PatternFly reference implementation.

28 lines (25 loc) 732 B
// @ts-nocheck /** * @param parent * @param child */ export default function contains(parent: Element, child: Element) { // $FlowFixMe: hasOwnProperty doesn't seem to work in tests const isShadow = Boolean(child.getRootNode && child.getRootNode().host); // First, attempt with faster native method if (parent.contains(child)) { return true; } // then fallback to custom implementation with Shadow DOM support else if (isShadow) { let next = child; do { if (next && parent.isSameNode(next)) { return true; } // $FlowFixMe: need a better way to handle this... next = next.parentNode || next.host; } while (next); } // Give up, the result is false return false; }