Skip to content

Commit

Permalink
[ClickAwayListener] Support other documents (#18701)
Browse files Browse the repository at this point in the history
  • Loading branch information
Izhaki authored and oliviertassinari committed Dec 6, 2019
1 parent 8ba3283 commit 0090249
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/material-ui/src/ClickAwayListener/ClickAwayListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,14 @@ const ClickAwayListener = React.forwardRef(function ClickAwayListener(props, ref
React.useEffect(() => {
if (touchEvent !== false) {
const mappedTouchEvent = mapEventPropToEvent(touchEvent);
const doc = ownerDocument(nodeRef.current);

document.addEventListener(mappedTouchEvent, handleClickAway);
document.addEventListener('touchmove', handleTouchMove);
doc.addEventListener(mappedTouchEvent, handleClickAway);
doc.addEventListener('touchmove', handleTouchMove);

return () => {
document.removeEventListener(mappedTouchEvent, handleClickAway);
document.removeEventListener('touchmove', handleTouchMove);
doc.removeEventListener(mappedTouchEvent, handleClickAway);
doc.removeEventListener('touchmove', handleTouchMove);
};
}

Expand All @@ -96,10 +97,12 @@ const ClickAwayListener = React.forwardRef(function ClickAwayListener(props, ref
React.useEffect(() => {
if (mouseEvent !== false) {
const mappedMouseEvent = mapEventPropToEvent(mouseEvent);
document.addEventListener(mappedMouseEvent, handleClickAway);
const doc = ownerDocument(nodeRef.current);

doc.addEventListener(mappedMouseEvent, handleClickAway);

return () => {
document.removeEventListener(mappedMouseEvent, handleClickAway);
doc.removeEventListener(mappedMouseEvent, handleClickAway);
};
}

Expand Down

0 comments on commit 0090249

Please sign in to comment.