@react-md/utils
Version:
General utils for react-md.
41 lines • 1.37 kB
JavaScript
/**
* Typeguard that will check if the provided checkable thing is a
* MutableRefObject or just an HTMLElement.
*
* @internal
*/
var isMutableRefObject = function (thing) {
return !!thing &&
typeof thing.current !== "undefined";
};
/**
* Gets the HTMLElement or null from the checkable thing.
*
* @internal
*/
var getElement = function (thing) {
if (isMutableRefObject(thing)) {
return thing.current;
}
return thing;
};
/**
* Checks if a container element contains another element as a child while
* allowing for nulls or a MutableRefObject of HTMLElement or null. Mostly just
* a convenience function that should be used internally.
*
* @param container - The element to use as a container element. This can be an
* HTMLElement, null, or a MutableRefObject of HTMLElement or null.
* @param child - The element that might be a child of the container
* element. This can be an HTMLElement, null, or a MutableRefObject of
* HTMLElement or null.
* @returns True if the container contains the child element and both the
* container and child are valid HTMLElements (not null).
* @internal
*/
export function containsElement(container, child) {
container = getElement(container);
child = getElement(child);
return !!(container && child && container.contains(child));
}
//# sourceMappingURL=containsElement.js.map