Skip to content

Commit

Permalink
Fix #6000: Improved closeOnEscape handling (#6012)
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware authored Feb 19, 2024
1 parent 66c9da4 commit 325a451
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions components/lib/hooks/useDisplayOrder.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,22 @@ export const useDisplayOrder = (group, isVisible = true) => {

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

const newDisplayOrder = groupToDisplayedElements[group].length + 1;
const newDisplayOrder = groupToDisplayedElements[group].push(uid);

groupToDisplayedElements[group].push(uid);
setDisplayOrder(newDisplayOrder);

return () => {
delete groupToDisplayedElements[group][newDisplayOrder];
const lastOrder = groupToDisplayedElements[group].findLastIndex((el) => el !== undefined);
delete groupToDisplayedElements[group][newDisplayOrder - 1];

// Reduce array length, by removing undefined elements at the end of array:
groupToDisplayedElements[group].splice(lastOrder + 1);
const lastIndex = groupToDisplayedElements[group].length - 1;
const lastOrder = groupToDisplayedElements[group].findLastIndex((el) => el !== undefined);

if (lastOrder !== lastIndex) groupToDisplayedElements[group].splice(lastOrder + 1);

setDisplayOrder(undefined);
};
Expand Down

0 comments on commit 325a451

Please sign in to comment.