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

Fix #5767: Global Escape key allow duplicate overlays #5770

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion components/lib/cascadeselect/CascadeSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const CascadeSelect = React.memo(
callback: () => {
hide();
},
when: overlayVisibleState,
when: overlayVisibleState && cascadeSelectOverlayDisplayOrder,
priority: [ESC_KEY_HANDLING_PRIORITIES.CASCADE_SELECT, cascadeSelectOverlayDisplayOrder]
});

Expand Down
2 changes: 1 addition & 1 deletion components/lib/confirmpopup/ConfirmPopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const ConfirmPopup = React.memo(
hide('hide');
}
},
when: visibleState,
when: visibleState && displayOrder,
priority: [ESC_KEY_HANDLING_PRIORITIES.DIALOG, displayOrder]
});

Expand Down
2 changes: 1 addition & 1 deletion components/lib/dialog/Dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const Dialog = React.forwardRef((inProps, ref) => {
onClose(event);
}
},
when: visibleState,
when: visibleState && displayOrder,
priority: [ESC_KEY_HANDLING_PRIORITIES.DIALOG, displayOrder]
});

Expand Down
5 changes: 2 additions & 3 deletions components/lib/hooks/useDisplayOrder.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ const groupToDisplayedElements = {};

export const useDisplayOrder = (group, isVisible = true) => {
const [uid] = React.useState(() => UniqueComponentId());

const [displayOrder, setDisplayOrder] = React.useState();
const [displayOrder, setDisplayOrder] = React.useState(0);

React.useEffect(() => {
if (isVisible) {
if (!(group in groupToDisplayedElements)) {
groupToDisplayedElements[group] = [];
}

const newDisplayOrder = groupToDisplayedElements[group].length;
const newDisplayOrder = groupToDisplayedElements[group].length + 1;

groupToDisplayedElements[group].push(uid);
setDisplayOrder(newDisplayOrder);
Expand Down
8 changes: 3 additions & 5 deletions components/lib/hooks/useGlobalOnEscapeKey.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DomHandler } from '../utils/Utils';
import { useEffect } from 'react';
import { DomHandler } from '../utils/Utils';

/**
* Priorities of different components (bigger number handled first)
Expand Down Expand Up @@ -42,13 +42,11 @@ const globalEscKeyHandlingLogic = {
*/
onGlobalKeyDown(event) {
// Do nothing if not an "esc" key is pressed:
if (event.key !== 'Esc' && event.key !== 'Escape') return;
if (event.code !== 'Escape') return;

const escKeyListeners = globalEscKeyHandlingLogic.escKeyListeners;
const maxPrimaryPriority = Math.max(...escKeyListeners.keys());

const theMostImportantEscHandlersSet = escKeyListeners.get(maxPrimaryPriority);

const maxSecondaryPriority = Math.max(...theMostImportantEscHandlersSet.keys());
const theMostImportantEscHandler = theMostImportantEscHandlersSet.get(maxSecondaryPriority);

Expand Down Expand Up @@ -106,5 +104,5 @@ export const useGlobalOnEscapeKey = ({ callback, when, priority }) => {
if (!when) return;

return globalEscKeyHandlingLogic.addListener(callback, priority);
}, [when, callback, priority]);
}, [callback, when, priority]);
};
2 changes: 1 addition & 1 deletion components/lib/menu/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const Menu = React.memo(
callback: (event) => {
hide(event);
},
when: visibleState && props.popup && props.closeOnEscape,
when: visibleState && props.popup && props.closeOnEscape && popupMenuDisplayOrder,
priority: [ESC_KEY_HANDLING_PRIORITIES.MENU, popupMenuDisplayOrder]
});

Expand Down
2 changes: 1 addition & 1 deletion components/lib/overlaypanel/OverlayPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const OverlayPanel = React.forwardRef((inProps, ref) => {
callback: () => {
hide();
},
when: visibleState && props.closeOnEscape,
when: visibleState && props.closeOnEscape && overlayPanelDisplayOrder,
priority: [ESC_KEY_HANDLING_PRIORITIES.OVERLAY_PANEL, overlayPanelDisplayOrder]
});

Expand Down
2 changes: 1 addition & 1 deletion components/lib/password/Password.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const Password = React.memo(
callback: () => {
hide();
},
when: overlayVisibleState && props.feedback,
when: overlayVisibleState && props.feedback && passwordDisplayOrder,
priority: [ESC_KEY_HANDLING_PRIORITIES.PASSWORD, passwordDisplayOrder]
});
const [bindOverlayListener, unbindOverlayListener] = useOverlayListener({
Expand Down
2 changes: 1 addition & 1 deletion components/lib/sidebar/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const Sidebar = React.forwardRef((inProps, ref) => {
callback: (event) => {
onClose(event);
},
when: visibleState && props.closeOnEscape,
when: visibleState && props.closeOnEscape && sidebarDisplayOrder,
priority: [ESC_KEY_HANDLING_PRIORITIES.SIDEBAR, sidebarDisplayOrder]
});

Expand Down
2 changes: 1 addition & 1 deletion components/lib/slidemenu/SlideMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const SlideMenu = React.memo(
callback: (event) => {
hide(event);
},
when: visibleState && props.popup && props.closeOnEscape,
when: visibleState && props.popup && props.closeOnEscape && slideMenuDisplayOrder,
priority: [ESC_KEY_HANDLING_PRIORITIES.SLIDE_MENU, slideMenuDisplayOrder]
});

Expand Down
2 changes: 1 addition & 1 deletion components/lib/speeddial/SpeedDial.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const SpeedDial = React.memo(
callback: () => {
hide();
},
when: visible,
when: visible && speedDialDisplayOrder,
priority: [ESC_KEY_HANDLING_PRIORITIES.SPEED_DIAL, speedDialDisplayOrder]
});

Expand Down
2 changes: 1 addition & 1 deletion components/lib/splitbutton/SplitButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const SplitButton = React.memo(
callback: () => {
hide();
},
when: overlayVisibleState,
when: overlayVisibleState && overlayDisplayOrder,
priority: [ESC_KEY_HANDLING_PRIORITIES.SPLIT_BUTTON, overlayDisplayOrder]
});

Expand Down
Loading