Skip to content

Commit 40cde80

Browse files
committed
Update ContextMenu.react.js
1 parent 52c4652 commit 40cde80

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/components/ContextMenu/ContextMenu.react.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const getPositionToFitVisibleScreen = (ref, offset = 0, mainItemCount = 0, subIt
2727
const projectedTop = elBox.top + y + offset;
2828
const projectedBottom = projectedTop + elBox.height;
2929

30-
const shouldApplyOffset = subItemCount > mainItemCount;
30+
const shouldApplyOffset = mainItemCount === 0 || subItemCount > mainItemCount;
3131
if (shouldApplyOffset && projectedTop >= upperLimit && projectedBottom <= lowerLimit) {
3232
y += offset;
3333
}
@@ -36,7 +36,10 @@ const getPositionToFitVisibleScreen = (ref, offset = 0, mainItemCount = 0, subIt
3636
if (prevEl) {
3737
const prevElBox = prevEl.getBoundingClientRect();
3838
const prevElStyle = window.getComputedStyle(prevEl);
39-
const prevElTop = parseInt(prevElStyle.top, 10);
39+
const rawTop = prevElStyle.top;
40+
41+
const parsedTop = parseInt(rawTop, 10);
42+
const prevElTop = Number.isFinite(parsedTop) ? parsedTop : prevElBox.top;
4043

4144
if (!shouldApplyOffset) {
4245
y = prevElTop + offset;
@@ -65,7 +68,7 @@ const MenuSection = ({ level, items, path, setPath, hide, parentItemCount = 0 })
6568
items.length
6669
);
6770
newPosition && setPosition(newPosition);
68-
}, [sectionRef]);
71+
}, [sectionRef, path, level, items.length, parentItemCount]);
6972

7073
const style = position
7174
? {

0 commit comments

Comments
 (0)