UNPKG

framer-motion

Version:

An open source and production-ready motion library for React on the web

20 lines (19 loc) • 480 B
/** * Recursively traverse up the tree to check whether the provided child node * is the parent or a descendant of it. * * @param parent - Element to find * @param child - Element to test against parent */ export const isNodeOrChild = ( parent: Element, child?: Element | null ): boolean => { if (!child) { return false } else if (parent === child) { return true } else { return isNodeOrChild(parent, child.parentElement) } }