fix(context menu): Context menus for edge-proximate measurements are partially obscured. (#4727)
This commit is contained in:
parent
eb854ac2cb
commit
61699d00b6
@ -1,14 +1,33 @@
|
|||||||
import React from 'react';
|
import React, { useEffect, useRef } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import Typography from '../Typography';
|
import Typography from '../Typography';
|
||||||
import { Icons } from '@ohif/ui-next';
|
import { Icons } from '@ohif/ui-next';
|
||||||
|
|
||||||
const ContextMenu = ({ items, ...props }) => {
|
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 + boundingClientRect.height > window.innerHeight) {
|
||||||
|
props.defaultPosition.y = props.defaultPosition.y - boundingClientRect.height;
|
||||||
|
}
|
||||||
|
if (boundingClientRect.right + boundingClientRect.width > window.innerWidth) {
|
||||||
|
props.defaultPosition.x = props.defaultPosition.x - boundingClientRect.width;
|
||||||
|
}
|
||||||
|
}, [props.defaultPosition]);
|
||||||
|
|
||||||
if (!items) {
|
if (!items) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
ref={contextMenuRef}
|
||||||
data-cy="context-menu"
|
data-cy="context-menu"
|
||||||
className="bg-secondary-dark relative z-50 block w-48 rounded"
|
className="bg-secondary-dark relative z-50 block w-48 rounded"
|
||||||
onContextMenu={e => e.preventDefault()}
|
onContextMenu={e => e.preventDefault()}
|
||||||
@ -35,6 +54,10 @@ const ContextMenu = ({ items, ...props }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
ContextMenu.propTypes = {
|
ContextMenu.propTypes = {
|
||||||
|
defaultPosition: PropTypes.shape({
|
||||||
|
x: PropTypes.number,
|
||||||
|
y: PropTypes.number,
|
||||||
|
}),
|
||||||
items: PropTypes.arrayOf(
|
items: PropTypes.arrayOf(
|
||||||
PropTypes.shape({
|
PropTypes.shape({
|
||||||
label: PropTypes.string.isRequired,
|
label: PropTypes.string.isRequired,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user