diff options
Diffstat (limited to 'popperjs/package/lib/dom-utils/contains.js.flow')
-rw-r--r-- | popperjs/package/lib/dom-utils/contains.js.flow | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/popperjs/package/lib/dom-utils/contains.js.flow b/popperjs/package/lib/dom-utils/contains.js.flow new file mode 100644 index 0000000..3164792 --- /dev/null +++ b/popperjs/package/lib/dom-utils/contains.js.flow @@ -0,0 +1,25 @@ +// @flow +import { isShadowRoot } from './instanceOf'; + +export default function contains(parent: Element, child: Element) { + const rootNode = child.getRootNode && child.getRootNode(); + + // First, attempt with faster native method + if (parent.contains(child)) { + return true; + } + // then fallback to custom implementation with Shadow DOM support + else if (rootNode && isShadowRoot(rootNode)) { + let next = child; + do { + if (next && parent.isSameNode(next)) { + return true; + } + // $FlowFixMe[prop-missing]: need a better way to handle this... + next = next.parentNode || next.host; + } while (next); + } + + // Give up, the result is false + return false; +} |