@fluentui/dom-utilities
Version:
DOM utilities for use within Fluent web components
16 lines • 1.14 kB
JavaScript
import { findElementRecursive } from './findElementRecursive';
import { DATA_PORTAL_ATTRIBUTE } from './setPortalAttribute';
/**
* Determine whether a target is within a portal from perspective of root or optional parent.
* This function only works against portal components that use the setPortalAttribute function.
* If both parent and child are within the same portal this function will return false.
* @param target - Element to query portal containment status of.
* @param parent - Optional parent perspective. Search for containing portal stops at parent
* (or root if parent is undefined or invalid.)
*/
export function portalContainsElement(target, parent, doc) {
var _a;
var elementMatch = findElementRecursive(target, function (testElement) { var _a; return parent === testElement || !!((_a = testElement.hasAttribute) === null || _a === void 0 ? void 0 : _a.call(testElement, DATA_PORTAL_ATTRIBUTE)); }, doc);
return elementMatch !== null && !!((_a = elementMatch.hasAttribute) === null || _a === void 0 ? void 0 : _a.call(elementMatch, DATA_PORTAL_ATTRIBUTE));
}
//# sourceMappingURL=portalContainsElement.js.map