Skip to content
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
20 changes: 16 additions & 4 deletions src/components/ContextMenu/ContextMenu.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import PropTypes from 'lib/PropTypes';
import React, { useState, useEffect, useRef } from 'react';
import React, { useState, useEffect, useLayoutEffect, useRef } from 'react';
import styles from 'components/ContextMenu/ContextMenu.scss';

const getPositionToFitVisibleScreen = (ref, offset = 0) => {
Expand Down Expand Up @@ -65,7 +65,7 @@ const MenuSection = ({ level, items, path, setPath, hide, hoveredItemOffset }) =
const basePosition = useRef(null);
const initialParentScrollTop = useRef(0);

useEffect(() => {
useLayoutEffect(() => {
// Use the actual pixel offset of the hovered item instead of index-based calculation
const newPosition = getPositionToFitVisibleScreen(sectionRef, hoveredItemOffset);
if (newPosition) {
Expand Down Expand Up @@ -110,7 +110,11 @@ const MenuSection = ({ level, items, path, setPath, hide, hoveredItemOffset }) =
opacity: 1,
position: 'absolute',
}
: {};
: {
opacity: 0,
position: 'absolute',
pointerEvents: 'none',
};

return (
<ul ref={sectionRef} className={styles.category} style={style}>
Expand All @@ -119,8 +123,16 @@ const MenuSection = ({ level, items, path, setPath, hide, hoveredItemOffset }) =
const newPath = path.slice(0, level + 1);
newPath.push(index);
// Get the actual pixel offset of the hovered item relative to its parent
// Using getBoundingClientRect for accuracy regardless of offsetParent chain
const itemElement = event.currentTarget;
const itemOffset = itemElement.offsetTop;
const parentElement = itemElement.closest('ul');
if (!parentElement) {
setPath(newPath, 0);
return;
}
const itemRect = itemElement.getBoundingClientRect();
const parentRect = parentElement.getBoundingClientRect();
const itemOffset = itemRect.top - parentRect.top + parentElement.scrollTop;
setPath(newPath, itemOffset);
};

Expand Down
Loading