Skip to content

Commit

Permalink
context menu position fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MrRobz committed Sep 26, 2021
1 parent c5e66f2 commit 14f3973
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ export const useContextMenu = () => {
if (clickedIconCard) {
event.preventDefault();

setAnchorPoint({ x: event.pageX, y: event.pageY });
setAnchorPoint({
x: event.pageX,
y: event.pageY,
});
setClickedIconId(clickedIconCard.getAttribute('data-icon-card-id'));
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import { ipcRenderer } from 'electron';
import { useContextMenu } from './hooks/useContextMenu';
import { deleteIcon } from './utils';

export const IconContextMenu: FC = () => {
export const IconContextMenu: FC<{
parentDom: HTMLDivElement;
}> = ({ parentDom }) => {
const queryClient = useQueryClient();
const { anchorPoint, clickedIconId } = useContextMenu();

Expand Down Expand Up @@ -63,7 +65,12 @@ export const IconContextMenu: FC = () => {
}

return (
<ContextMenu style={{ top: anchorPoint.y - 65, left: anchorPoint.x - 260 }}>
<ContextMenu
style={{
top: anchorPoint.y + parentDom.scrollTop - parentDom.clientTop - 60,
left: anchorPoint.x + parentDom.scrollLeft - parentDom.clientLeft - 260,
}}
>
<ContextMenu.Item onClick={onCopy}>
<CopyIcon className="mr-2" />
<div>Copy as React</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const IconCardsSection: FC<Props> = ({
))}
</div>

<IconContextMenu />
<IconContextMenu parentDom={wrapperDivRef.current} />
</div>
);
};

0 comments on commit 14f3973

Please sign in to comment.