Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ClickAwayListener] Fix support for removed DOM node #20409

Merged
merged 4 commits into from
Apr 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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