Skip to content

Commit 0090249

Browse files
Izhakioliviertassinari
authored andcommitted
[ClickAwayListener] Support other documents (#18701)
1 parent 8ba3283 commit 0090249

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,14 @@ const ClickAwayListener = React.forwardRef(function ClickAwayListener(props, ref
8080
React.useEffect(() => {
8181
if (touchEvent !== false) {
8282
const mappedTouchEvent = mapEventPropToEvent(touchEvent);
83+
const doc = ownerDocument(nodeRef.current);
8384

84-
document.addEventListener(mappedTouchEvent, handleClickAway);
85-
document.addEventListener('touchmove', handleTouchMove);
85+
doc.addEventListener(mappedTouchEvent, handleClickAway);
86+
doc.addEventListener('touchmove', handleTouchMove);
8687

8788
return () => {
88-
document.removeEventListener(mappedTouchEvent, handleClickAway);
89-
document.removeEventListener('touchmove', handleTouchMove);
89+
doc.removeEventListener(mappedTouchEvent, handleClickAway);
90+
doc.removeEventListener('touchmove', handleTouchMove);
9091
};
9192
}
9293

@@ -96,10 +97,12 @@ const ClickAwayListener = React.forwardRef(function ClickAwayListener(props, ref
9697
React.useEffect(() => {
9798
if (mouseEvent !== false) {
9899
const mappedMouseEvent = mapEventPropToEvent(mouseEvent);
99-
document.addEventListener(mappedMouseEvent, handleClickAway);
100+
const doc = ownerDocument(nodeRef.current);
101+
102+
doc.addEventListener(mappedMouseEvent, handleClickAway);
100103

101104
return () => {
102-
document.removeEventListener(mappedMouseEvent, handleClickAway);
105+
doc.removeEventListener(mappedMouseEvent, handleClickAway);
103106
};
104107
}
105108

0 commit comments

Comments
 (0)