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

Cross-browser event path #678

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
19 changes: 17 additions & 2 deletions frontend/src/static/js/components/_shared/popup/PopupContent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,23 @@ export function PopupContent(props) {

const domElem = findDOMNode(wrapperRef.current);

if (-1 === ev.path.indexOf(domElem)) {
hide();
// To avoid this error on Firefox:
// Uncaught TypeError: e.path is undefined
// And this error on Chromium:
// Uncaught TypeError: Cannot read properties of undefined (reading 'indexOf')
//
// https://stackoverflow.com/a/39245638/3405291
//
// It allows for both the old way and the new, standard way.
// So will do its best cross-browser.
var path = ev.path || (ev.composedPath && ev.composedPath());
if (path) {
if (-1 === path.indexOf(domElem)) {
hide();
}
} else {
console.log("This browser doesn't supply event path information")
// TODO: Should call hide()?
}
}, []);

Expand Down