Don't show context menu if there's no items

Summary:
If the creator callback to useContextMenu returns `[]`, don't show a blank context menu. Instead, return. This also skips the stopPropagation, so parent context menu handlers can be used.

In practice, this is used for right clicking on a remote bookmark to not show a menu, and instead continue to delegate to `<Commit>`'s context menu.

Reviewed By: quark-zju

Differential Revision: D55938828

fbshipit-source-id: 25e43136a76c4efeb26c89e5c818380e1d4991c1
This commit is contained in:
Evan Krause 2024-04-09 15:34:08 -07:00 committed by Facebook GitHub Bot
parent aa6fa5a662
commit dd30de9bb2

View File

@ -32,7 +32,11 @@ export function useContextMenu<T>(
const setState = useSetAtom(contextMenuState);
return e => {
const zoom = getZoomLevel();
setState({x: e.clientX / zoom, y: e.clientY / zoom, items: creator()});
const items = creator();
if (items.length === 0) {
return;
}
setState({x: e.clientX / zoom, y: e.clientY / zoom, items});
e.preventDefault();
e.stopPropagation();