Skip to content

Commit c83fbaf

Browse files
authored
[ClickAwayListener] Fix support for removed DOM node (#20409)
1 parent 078fd1e commit c83fbaf

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

packages/material-ui/src/ClickAwayListener/ClickAwayListener.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,20 @@ const ClickAwayListener = React.forwardRef(function ClickAwayListener(props, ref
6363
return;
6464
}
6565

66-
// Multi window support
67-
const doc = ownerDocument(nodeRef.current);
68-
69-
if (
70-
doc.documentElement &&
71-
doc.documentElement.contains(event.target) &&
72-
!nodeRef.current.contains(event.target)
73-
) {
66+
let insideDOM;
67+
68+
// If not enough, can use https://github.com/DieterHolvoet/event-propagation-path/blob/master/propagationPath.js
69+
if (event.composedPath) {
70+
insideDOM = event.composedPath().indexOf(nodeRef.current) > -1;
71+
} else {
72+
const doc = ownerDocument(nodeRef.current);
73+
// TODO v6 remove dead logic https://caniuse.com/#search=composedPath.
74+
insideDOM =
75+
!(doc.documentElement && doc.documentElement.contains(event.target)) ||
76+
nodeRef.current.contains(event.target);
77+
}
78+
79+
if (!insideDOM) {
7480
onClickAway(event);
7581
}
7682
});

packages/material-ui/src/Tooltip/Tooltip.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ const Tooltip = React.forwardRef(function Tooltip(props, ref) {
444444
...other,
445445
...children.props,
446446
className: clsx(other.className, children.props.className),
447+
ref: handleRef,
447448
};
448449

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

503504
return (
504505
<React.Fragment>
505-
{React.cloneElement(children, { ref: handleRef, ...childrenProps })}
506+
{React.cloneElement(children, childrenProps)}
506507
<Popper
507508
className={clsx(classes.popper, {
508509
[classes.popperInteractive]: interactive,

0 commit comments

Comments
 (0)