Skip to content

Commit dbfef27

Browse files
authored
Fix leaderboard admin closing when trying to remove a leaderboard (#4691)
1 parent 72b69e4 commit dbfef27

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

newIDE/app/src/EventsSheet/InlinePopover.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
shouldSubmit,
1212
shouldValidate,
1313
} from '../UI/KeyboardShortcuts/InteractionKeys';
14+
import { doesPathContainDialog } from '../UI/MaterialUISpecificUtil';
1415

1516
const styles = {
1617
popover: {
@@ -54,10 +55,16 @@ export default function InlinePopover(props: Props) {
5455
return (
5556
<ClickAwayListener
5657
onClickAway={event => {
58+
// Clicks on dialogs (or their backdrop element) generated by
59+
// the AlertProvider seem to trigger this click away listener
60+
// even if they are displayed above the InlinePopover element.
61+
// To avoid this, we need to check the click is not made on a dialog.
62+
if (doesPathContainDialog(event.path)) {
63+
return;
64+
}
5765
// For a popover, clicking/touching away means validating,
5866
// as it's very easy to do it and almost the only way to do it on a touch screen.
5967
// The user can cancel with Escape.
60-
6168
if (event instanceof MouseEvent) {
6269
// onClickAway is triggered on a "click" (which can actually happen
6370
// on a touchscreen too!).

newIDE/app/src/UI/MaterialUISpecificUtil.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,19 @@ export const getMuiCheckboxValue = (element: HTMLElement): boolean => {
4949
}
5050
return true;
5151
};
52+
53+
export const doesPathContainDialog = (path: Array<Element>): boolean => {
54+
// Dialogs root elements are directly placed in the body element.
55+
// So the path is global > document > html > body > dialog.
56+
try {
57+
return isElementADialog(path[path.length - 5], { isVisible: true });
58+
} catch (error) {
59+
console.error(
60+
`An error occurred when determining if path ${path.join(
61+
' > '
62+
)} leads to a dialog`,
63+
error
64+
);
65+
return false;
66+
}
67+
};

0 commit comments

Comments
 (0)