Skip to content

Commit

Permalink
fix: issue with onMouseLeave and shadow DOM
Browse files Browse the repository at this point in the history
fix #113
  • Loading branch information
jedwards1211 committed Dec 12, 2022
1 parent a783b67 commit 101ce11
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,17 +585,24 @@ export function bindDialog({ isOpen, close }: PopupState): {
}
}

function getPopup({ popupId }: PopupState): Element | null | undefined {
return popupId && typeof document !== 'undefined'
? document.getElementById(popupId) // eslint-disable-line no-undef
: null
function getPopup(
element: Element,
{ popupId }: PopupState
): Element | null | undefined {
if (!popupId) return null
const rootNode: any =
typeof element.getRootNode === 'function' ? element.getRootNode() : document
if (typeof rootNode.getElementById === 'function') {
return rootNode.getElementById(popupId)
}
return null
}

function isElementInPopup(element: Element, popupState: PopupState): boolean {
const { anchorEl, _childPopupState } = popupState
return (
isAncestor(anchorEl, element) ||
isAncestor(getPopup(popupState), element) ||
isAncestor(getPopup(element, popupState), element) ||
(_childPopupState != null && isElementInPopup(element, _childPopupState))
)
}
Expand Down

0 comments on commit 101ce11

Please sign in to comment.