The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 16:00 UTC
fix(web): a context submenu near the right edge no longer covers its parent menu (#23666)
Co-authored-by: Rodrigo Brechard <rodrigo@clubtidy.fr> Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Rodrigo Brechard committed
Nov 14, 2026 at 09:35 UTC
947c056894886a4301e3977096cdfb4853d5fdad
2 files changed
+41
-5
apps/web/src/contextMenuFallback.test.ts
+29
@@ -238,6 +238,35 @@ describe("showContextMenuFallback", () => {
238
await expect(selectionPromise).resolves.toBe("rename");
239
});
240
241
+ it.each([
242
+ // Flips left of the parent menu instead of being clamped over it.
243
+ { innerWidth: 400, triggerLeft: 200, submenuLeft: 16 },
244
+ // Neither side fits; the right has more room, so it stays there, clamped.
245
+ { innerWidth: 300, triggerLeft: 4, submenuLeft: 116 },
246
+ ])(
247
+ "places an overflowing submenu on the side with more room ($innerWidth)",
248
+ ({ innerWidth, triggerLeft, submenuLeft }) => {
249
+ vi.stubGlobal("window", { ...window, innerWidth });
250
+
251
+ void showContextMenuFallback(
252
+ [
253
+ {
254
+ id: "group",
255
+ label: "Group with",
256
+ children: [{ id: "terminal-1", label: "Terminal 1" }],
257
+ },
258
+ ],
259
+ { x: triggerLeft, y: 0 },
260
+ );
261
+ const trigger = findButton("Group with")!;
262
+ trigger.style.left = `${triggerLeft}px`;
263
+ trigger.dispatchEvent(new MouseEvent("click", { bubbles: true }));
264
+
265
+ const submenu = findButton("Terminal 1")!.parent!.parent!;
266
+ expect(submenu.getBoundingClientRect().left).toBe(submenuLeft);
267
+ },
268
+ );
269
+
270
it("shows an item's detail beside its label and reads both to screen readers", () => {
271
void showContextMenuFallback([{ id: "snooze:hour", label: "In 1 hour", detail: "3:00 PM" }]);
272
const button = findButton("In 1 hour");
apps/web/src/contextMenuFallback.ts
+12
-5
@@ -551,10 +551,6 @@ export function showContextMenuFallback<T extends string>(
551
if (!childMenu) {
552
return;
553
}
554
- const childRect = childMenu.getBoundingClientRect();
555
- if (childRect.right > window.innerWidth) {
556
- clampMenuPosition(childMenu, rect.left - childRect.width - 4, rect.top);
557
- }
554
if (focusFirstItem) {
555
[...childMenu.querySelectorAll<HTMLButtonElement>("button")]
556
.find((childButton) => !childButton.disabled)
@@ -599,7 +595,18 @@ export function showContextMenuFallback<T extends string>(
595
submenuTriggerStack[level] = parentTrigger;
596
597
requestAnimationFrame(() => {
602
- clampMenuPosition(menu, preferredLeft, preferredTop);
598
+ if (!parentTrigger) {
599
+ clampMenuPosition(menu, preferredLeft, preferredTop);
600
+ return;
601
+ }
602
+ // A fixed menu near the right edge shrinks to the space left; measure its real width.
603
+ menu.style.width = "max-content";
604
+ menu.style.maxWidth = "min(24rem, calc(100vw - 0.5rem))";
605
+ const { width } = menu.getBoundingClientRect();
606
+ const roomLeft = parentTrigger.getBoundingClientRect().left - 4;
607
+ const roomRight = window.innerWidth - preferredLeft;
608
+ const flipLeft = width > roomRight && roomLeft > roomRight;
609
+ clampMenuPosition(menu, flipLeft ? roomLeft - width : preferredLeft, preferredTop);
610
});
611
};
612