fix(context-menu): Move the reposition logic from the context menu to the dialog component. (#5060)
This commit is contained in:
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()}
|
||||
|
||||
Reference in new issue
Block a user