UNPKG

@limetech/lime-elements

Version:
31 lines (30 loc) 951 B
/** * Check if an element is a descendant of another * * If the child element is a descendant of a limel-portal, this function will * go back through the portal and check the original tree recursively * * @param element - the parent element * @param child - the child element to check * @returns `true` if child is a descendant of element, taking * portals into account */ export function portalContains(element, child) { var _a; if (element.contains(child) || ((_a = element.shadowRoot) === null || _a === void 0 ? void 0 : _a.contains(child))) { return true; } const parent = findParent(child); if (!parent) { return false; } return portalContains(element, parent); } function findParent(element) { const portal = element.closest('.limel-portal--container'); if (portal) { return portal.portalSource; } const rootNode = element.getRootNode(); return rootNode.host; }