Skip to content

Commit

Permalink
[ClickAwayListener] Fix support for removed DOM node (#20409)
Browse files Browse the repository at this point in the history
  • Loading branch information
seare-kidane authored Apr 5, 2020
1 parent 078fd1e commit c83fbaf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
22 changes: 14 additions & 8 deletions packages/material-ui/src/ClickAwayListener/ClickAwayListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,20 @@ const ClickAwayListener = React.forwardRef(function ClickAwayListener(props, ref
return;
}

// Multi window support
const doc = ownerDocument(nodeRef.current);

if (
doc.documentElement &&
doc.documentElement.contains(event.target) &&
!nodeRef.current.contains(event.target)
) {
let insideDOM;

// If not enough, can use https://github.com/DieterHolvoet/event-propagation-path/blob/master/propagationPath.js
if (event.composedPath) {
insideDOM = event.composedPath().indexOf(nodeRef.current) > -1;
} else {
const doc = ownerDocument(nodeRef.current);
// TODO v6 remove dead logic https://caniuse.com/#search=composedPath.
insideDOM =
!(doc.documentElement && doc.documentElement.contains(event.target)) ||
nodeRef.current.contains(event.target);
}

if (!insideDOM) {
onClickAway(event);
}
});
Expand Down
3 changes: 2 additions & 1 deletion packages/material-ui/src/Tooltip/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ const Tooltip = React.forwardRef(function Tooltip(props, ref) {
...other,
...children.props,
className: clsx(other.className, children.props.className),
ref: handleRef,
};

const interactiveWrapperListeners = {};
Expand Down Expand Up @@ -502,7 +503,7 @@ const Tooltip = React.forwardRef(function Tooltip(props, ref) {

return (
<React.Fragment>
{React.cloneElement(children, { ref: handleRef, ...childrenProps })}
{React.cloneElement(children, childrenProps)}
<Popper
className={clsx(classes.popper, {
[classes.popperInteractive]: interactive,
Expand Down

0 comments on commit c83fbaf

Please sign in to comment.