UNPKG

@mui/x-internals

Version:

Utility functions for the MUI X packages (internal use only).

21 lines (20 loc) 652 B
import ownerWindow from '@mui/utils/ownerWindow'; /** * Checks if a value is an HTMLElement, including elements from other iframes/realms. */ export function isHTMLElement(value) { if (typeof window === 'undefined' || value == null) { return false; } if (value instanceof HTMLElement) { return true; } // Cross-realm: must be an element node (nodeType 1) from another window. // The try/catch guards against detached/destroyed windows where accessing // `.HTMLElement` on the owner window may throw. try { return value.nodeType === 1 && value instanceof ownerWindow(value).HTMLElement; } catch { return false; } }