From 867d79b7c3444a987cd566ed133e2c78f4b2c0f2 Mon Sep 17 00:00:00 2001 From: jeffvli Date: Wed, 29 Sep 2021 04:33:35 -0700 Subject: [PATCH] Set calculated context menu position --- src/components/viewtypes/ListViewTable.tsx | 31 +++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/components/viewtypes/ListViewTable.tsx b/src/components/viewtypes/ListViewTable.tsx index 211778e..d97a232 100644 --- a/src/components/viewtypes/ListViewTable.tsx +++ b/src/components/viewtypes/ListViewTable.tsx @@ -250,6 +250,25 @@ const ListViewTable = ({ onSortColumn={handleSortColumn} onRowContextMenu={(rowData: any, e: any) => { e.preventDefault(); + + let pageX; + let pageY; + // Use ContextMenu width from the component + if (e.pageX + 190 >= window.innerWidth) { + pageX = e.pageX - 190; + } else { + pageX = e.pageX; + } + + // Use the calculated ContextMenu height + // numOfButtons * 30 + props.numOfDividers * 1.5 + const contextMenuHeight = 8 * 30 + 4 * 1.5; + if (e.pageY + contextMenuHeight >= window.innerHeight) { + pageY = e.pageY - contextMenuHeight; + } else { + pageY = e.pageY; + } + if ( (misc.contextMenu.show === false || misc.contextMenu.rowId !== rowData.uniqueId) && multiSelect.selected.filter((entry: any) => entry.uniqueId === rowData.uniqueId) @@ -258,17 +277,23 @@ const ListViewTable = ({ dispatch( setContextMenu({ show: true, - xPos: e.pageX, - yPos: e.pageY, + xPos: pageX, + yPos: pageY, rowId: rowData.uniqueId, type: nowPlaying ? 'nowPlaying' : multiSelect.selected[0].type, disabledOptions: disabledContextMenuOptions || [], }) ); } else { + dispatch(setSelectedSingle(rowData)); dispatch( setContextMenu({ - show: false, + show: true, + xPos: pageX, + yPos: pageY, + rowId: rowData.uniqueId, + type: nowPlaying ? 'nowPlaying' : multiSelect.selected[0].type, + disabledOptions: disabledContextMenuOptions || [], }) ); }