fix(context-menu): Move the reposition logic from the context menu to the dialog component. (#5060)

This commit is contained in:
Joe Boccanfuso authored and GitHub committed 2025-05-23 22:12:08 -04:00
1 parent fa9bbe3afc
commit cb814e6a60
3 files changed
+509 -496

No files matched your search

@@ -1,33 +1,15 @@
import React, { useEffect, useRef } from 'react';
import React from 'react';
import PropTypes from 'prop-types';
import Typography from '../Typography';
import { Icons } from '@ohif/ui-next';
const ContextMenu = ({ items, ...props }) => {
const contextMenuRef = useRef<HTMLDivElement>(null);
useEffect(() => {
if (!contextMenuRef?.current) {
return;
}
const contextMenu = contextMenuRef.current;
const boundingClientRect = contextMenu.getBoundingClientRect();
if (boundingClientRect.bottom > window.innerHeight) {
props.defaultPosition.y = props.defaultPosition.y - boundingClientRect.height;
}
if (boundingClientRect.right > window.innerWidth) {
props.defaultPosition.x = props.defaultPosition.x - boundingClientRect.width;
}
}, [props.defaultPosition]);
if (!items) {
return null;
}
return (
<div
ref={contextMenuRef}
data-cy="context-menu"
className="bg-secondary-dark relative z-50 block w-48 rounded"
onContextMenu={e => e.preventDefault()}