UX: Safe triangles for menus interactions

Hi, i would like to propose a ux improvement for menus interactions.

Safe triangles allow diagonal movement towards a sub-menu item by preventing the sub-menu from closing, as long as the user moves inside the "safe" area.

Here is an example of a safe triangle starting from the current pointer position

Here is an article that dives deeper into safe triangles

TIL - never knew about "safe triangles" (not being a designer) but now that you mention it, yes it's incredible annoying and it happens more often than one would think.

Screen Recording 2026-11-06 at 21.16.30-2

From an implementation PoV, in this case it's happening because the way the sub-menu appearing and disappearing is triggered. Submenu appears because a mouse click event happened on the menu item "rectangle" and the submenu disappears as soon as there is a mouseout event, i.e., the cursor moves out of the "rectangle" that defines the menu item that opened the submenu!

Since these menus are a stack of rectangles, it's hard to implement a triangle that would go over multiple menu items. I.e. a mouseout event would need to know that it's in a triangle and the submenu shouldn't disappear. That's too low-level for the jQuery/HTML graphics APIs.

A workaround might be a mouseover event on the submenu while having a timeout on the mouseout event. So that if a cursor moves out of the "rectangle" representing the menu item but moves over the submenu within (for example) 200 milliseconds then the submenu isn't hidden.

I'm not familiar with the node-red codebase so i can't say for sure how this could be implemented, but i played around a bit, and made this demo that can run just by pasting it in the console:

(() => {
  const ns = "http://www.w3.org/2000/svg";
  const svg = document.createElementNS(ns, "svg");

  Object.assign(svg.style, {
    position: "fixed",
    inset: "0",
    width: "100vw",
    height: "100vh",
    pointerEvents: "none",
    zIndex: "1000",
  });

  const tri = document.createElementNS(ns, "polygon");
  tri.setAttribute("fill", "red");
  tri.setAttribute("fill-opacity", "0.4");
  tri.style.pointerEvents = "auto";
  svg.append(tri);

  function clear() {
    tri.removeAttribute("points");
    svg.remove();
  }

  document.addEventListener(
    "mousemove",
    (e) => {
      if (e.target === tri) return;

      const li = e.target.closest?.("li.red-ui-menu-dropdown-submenu");
      if (!li) return clear();

      const anchorId = li.querySelector(":scope > a")?.id;
      const subMenu = anchorId && document.getElementById(anchorId + "-submenu");

      if (!subMenu) return clear();
      if (subMenu.contains(e.target)) return clear();

      const r = subMenu.getBoundingClientRect();
      if (!r.width || !r.height) return clear();

      const x = e.clientX < r.left ? r.left : r.right;
      tri.setAttribute("points", `${x},${r.top},${x},${r.bottom},${e.clientX},${e.clientY}`);

      if (svg.parentElement !== li) li.append(svg);
    },
    true,
  );
})();

This already works well.
Demo

Thanks for that solution. I hope you don't mind, I've added to my presenter mode node so that I don't have to go executing it in my console all the time!

I improved it a bit further, now it has a delay based on distance to the target.

(() => {
  const ns = "http://www.w3.org/2000/svg";
  const svg = document.createElementNS(ns, "svg");

  Object.assign(svg.style, {
    position: "fixed",
    inset: "0",
    width: "100vw",
    height: "100vh",
    pointerEvents: "none",
    zIndex: "1000",
  });

  const tri = document.createElementNS(ns, "polygon");
  tri.setAttribute("fill", "blue");
  tri.setAttribute("fill-opacity", "0.4");
  tri.style.pointerEvents = "auto";
  svg.append(tri);

  const MIN_DELAY = 200;
  const MAX_DELAY = 600;
  const MS_PER_PX = 1.2;

  const last = { tId: null, x: 0, y: 0, li: null, sub: null, delay: MIN_DELAY };

  function clear() {
    clearTimeout(last.tId);
    tri.removeAttribute("points");
    svg.remove();
  }

  function expire() {
    const { x, y, li, sub } = last;
    clear();
    if (!li) return;

    const under = document.elementFromPoint(x, y);
    if (under && (li.contains(under) || sub?.contains(under))) return;

    const init = { bubbles: true, cancelable: true, view: window, clientX: x, clientY: y, relatedTarget: under };

    //notify li that we are out
    li.dispatchEvent(new MouseEvent("mouseout", init));
    li.dispatchEvent(new MouseEvent("mouseleave", { ...init, bubbles: false }));

    //notifiy new target that we are hovering
    if (under) {
      under.dispatchEvent(new MouseEvent("mouseover", { ...init, relatedTarget: li }));
      under.dispatchEvent(new MouseEvent("mousemove", init));
    }
  }

  document.addEventListener(
    "mousemove",
    (e) => {
      if (e.target === tri) {
        last.x = e.clientX;
        last.y = e.clientY;
        clearTimeout(last.tId);
        last.tId = setTimeout(expire, last.delay);
        return;
      }

      const li = e.target.closest?.("li.red-ui-menu-dropdown-submenu");
      if (!li) return clear();

      const anchorId = li.querySelector(":scope > a")?.id;
      const subMenu = anchorId && document.getElementById(anchorId + "-submenu");

      if (!subMenu) return clear();
      if (subMenu.contains(e.target)) return clear();

      const r = subMenu.getBoundingClientRect();
      if (!r.width || !r.height) return clear();

      last.x = e.clientX;
      last.y = e.clientY;
      last.li = li;
      last.sub = subMenu;

      const x = e.clientX < r.left ? r.left : r.right;
      tri.setAttribute("points", `${x},${r.top},${x},${r.bottom},${e.clientX},${e.clientY}`);

      //compute the delay based on largest distance to submenu
      const d = Math.max(Math.hypot(x - e.clientX, r.top - e.clientY), Math.hypot(x - e.clientX, r.bottom - e.clientY));
      last.delay = Math.max(MIN_DELAY, Math.min(d * MS_PER_PX, MAX_DELAY));

      if (svg.parentElement !== li) li.append(svg);
    },
    true,
  );
})();