diff --git a/js/components/ContextMenuTarget.tsx b/js/components/ContextMenuTarget.tsx index 1567e842..5860ceee 100644 --- a/js/components/ContextMenuTarget.tsx +++ b/js/components/ContextMenuTarget.tsx @@ -1,19 +1,11 @@ import React, { useState, useRef, useEffect, useMemo } from "react"; import ContextMenu from "./ContextMenu"; -type DivProps = React.DetailedHTMLProps< - React.HTMLAttributes, - HTMLDivElement ->; - interface Props extends React.HTMLAttributes { - handle: React.ReactNode; + renderMenu: () => React.ReactNode; top?: boolean; bottom?: boolean; } -interface State { - selected: boolean; -} function getNodeOffset(node: HTMLDivElement | null) { if (node == null) { @@ -26,10 +18,18 @@ function getNodeOffset(node: HTMLDivElement | null) { return { top: rect.top + scrollTop, left: rect.left + scrollLeft }; } +// Trigger a context menu relative to the child element when the user +// left-clicks on the child. +// +// For a component that triggers relative to the user's cursor on right-click +// see ``. function ContextMenuTarget(props: Props) { const handleNode = useRef(null); const [selected, setSelected] = useState(false); useEffect(() => { + if (!selected) { + return; + } function handleGlobalClick(e: MouseEvent) { if ( selected && @@ -58,7 +58,7 @@ function ContextMenuTarget(props: Props) { { top: 0, left: 0 }; }, [selected]); - const { handle, children, top, bottom, ...passThroughProps } = props; + const { renderMenu, children, top, bottom, ...passThroughProps } = props; return (
setSelected(!selected)} > - {handle} + {children}
- {children} + {renderMenu()}
); diff --git a/js/components/ContextMenuWrapper.tsx b/js/components/ContextMenuWrapper.tsx index 774c95ba..b7df6ddd 100644 --- a/js/components/ContextMenuWrapper.tsx +++ b/js/components/ContextMenuWrapper.tsx @@ -6,11 +6,10 @@ interface Props { children: ReactNode; } -interface State { - selected: boolean; - offsetTop: number | null; - offsetLeft: number | null; -} +// Trigger a context menu at the user's cursor position when the user right +// clicks within this component. +// For a component that triggers relative to a given component when the user +// left-clicks see ``. // TODO: Consider using nested contexts to ensure we don't ever have multiple // non-nested context menus open at a time. diff --git a/js/components/EqualizerWindow/PresetsContextMenu.tsx b/js/components/EqualizerWindow/PresetsContextMenu.tsx index 2192a7e7..39bb8e00 100644 --- a/js/components/EqualizerWindow/PresetsContextMenu.tsx +++ b/js/components/EqualizerWindow/PresetsContextMenu.tsx @@ -17,19 +17,27 @@ interface DispatchProps { } const PresetsContextMenu = (props: DispatchProps) => ( - }> - - {builtin.presets.map(preset => ( - props.setEqFromObject(preset)} - label={preset.name} - /> - ))} -
- -
- + ( + <> + + {builtin.presets.map(preset => ( + props.setEqFromObject(preset)} + label={preset.name} + /> + ))} +
+ +
+ + + )} + > +
); diff --git a/js/components/MainWindow/ClutterBar.tsx b/js/components/MainWindow/ClutterBar.tsx index db9d6c80..01a27800 100644 --- a/js/components/MainWindow/ClutterBar.tsx +++ b/js/components/MainWindow/ClutterBar.tsx @@ -25,8 +25,8 @@ const ClutterBar = React.memo(() => { const doubled = useTypedSelector(Selectors.getDoubled); return (
- }> - + }> +
diff --git a/js/components/MainWindow/index.tsx b/js/components/MainWindow/index.tsx index bd06618a..2cd6a93c 100644 --- a/js/components/MainWindow/index.tsx +++ b/js/components/MainWindow/index.tsx @@ -88,9 +88,9 @@ const MainWindow = React.memo(({ analyser, filePickers }: Props) => { } + renderMenu={() => } > - + {mainShade && } diff --git a/js/components/PlaylistWindow/MiscOptionsContextMenu.tsx b/js/components/PlaylistWindow/MiscOptionsContextMenu.tsx index 12523206..3e65ba65 100644 --- a/js/components/PlaylistWindow/MiscOptionsContextMenu.tsx +++ b/js/components/PlaylistWindow/MiscOptionsContextMenu.tsx @@ -11,11 +11,15 @@ interface DispatchProps { const MiscOptionsContextMenu = (props: DispatchProps) => ( } + renderMenu={() => ( + + )} > - +
); diff --git a/js/components/PlaylistWindow/SortContextMenu.tsx b/js/components/PlaylistWindow/SortContextMenu.tsx index ab8de474..4a4c870a 100644 --- a/js/components/PlaylistWindow/SortContextMenu.tsx +++ b/js/components/PlaylistWindow/SortContextMenu.tsx @@ -22,12 +22,16 @@ const SortContextMenu = (props: DispatchProps) => ( } + renderMenu={() => ( + <> + +
+ + + + )} > - -
- - +
);