Browse Source

Set calculated context menu position

master
jeffvli 3 years ago
parent
commit
867d79b7c3
  1. 31
      src/components/viewtypes/ListViewTable.tsx

31
src/components/viewtypes/ListViewTable.tsx

@ -250,6 +250,25 @@ const ListViewTable = ({
onSortColumn={handleSortColumn} onSortColumn={handleSortColumn}
onRowContextMenu={(rowData: any, e: any) => { onRowContextMenu={(rowData: any, e: any) => {
e.preventDefault(); 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 ( if (
(misc.contextMenu.show === false || misc.contextMenu.rowId !== rowData.uniqueId) && (misc.contextMenu.show === false || misc.contextMenu.rowId !== rowData.uniqueId) &&
multiSelect.selected.filter((entry: any) => entry.uniqueId === rowData.uniqueId) multiSelect.selected.filter((entry: any) => entry.uniqueId === rowData.uniqueId)
@ -258,17 +277,23 @@ const ListViewTable = ({
dispatch( dispatch(
setContextMenu({ setContextMenu({
show: true, show: true,
xPos: e.pageX, xPos: pageX,
yPos: e.pageY, yPos: pageY,
rowId: rowData.uniqueId, rowId: rowData.uniqueId,
type: nowPlaying ? 'nowPlaying' : multiSelect.selected[0].type, type: nowPlaying ? 'nowPlaying' : multiSelect.selected[0].type,
disabledOptions: disabledContextMenuOptions || [], disabledOptions: disabledContextMenuOptions || [],
}) })
); );
} else { } else {
dispatch(setSelectedSingle(rowData));
dispatch( dispatch(
setContextMenu({ setContextMenu({
show: false, show: true,
xPos: pageX,
yPos: pageY,
rowId: rowData.uniqueId,
type: nowPlaying ? 'nowPlaying' : multiSelect.selected[0].type,
disabledOptions: disabledContextMenuOptions || [],
}) })
); );
} }

Loading…
Cancel
Save