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, 11:00 UTC
fix(web): composer suggestions stay reachable in short windows (#37179)
Co-authored-by: Grok 4.7 <noreply@x.ai> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Wout Stiens committed
Nov 15, 2026 at 13:47 UTC
cb251b9abc1403aa02e21e400d0b7f396a195e3c
6 files changed
+181
-7
apps/web/src/components/chat/ChatComposer.tsx
+1
-1
@@ -3517,7 +3517,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
3517
)}
3518
>
3519
{isStashMenuOpen && !composerMenuOpen && (
3520
- <ComposerCommandMenuLayer anchor={composerMenuAnchor}>
3520
+ <ComposerCommandMenuLayer anchor={composerMenuAnchor} canOverflowTop>
3521
<ComposerStashMenu
3522
composerFormRef={composerFormRef}
3523
entries={stashQueue}
apps/web/src/components/chat/ComposerCommandMenuLayer.tsx
+12
-5
@@ -21,12 +21,14 @@ function composerCommandMenuPositionsEqual(
21
export function ComposerCommandMenuLayer(props: {
22
anchor: HTMLElement | null;
23
children: ReactNode;
24
+ /** Keeps the 96px floor past the window top: the stash then loses its header, not its entries. */
25
+ canOverflowTop?: boolean;
26
}) {
27
+ const { anchor, canOverflowTop = false } = props;
28
const [position, setPosition] = useState<ComposerCommandMenuPosition | null>(null);
29
30
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- positions the menu from the composer's DOM rect, tracking window resize, scroll and ancestor resizes
31
useLayoutEffect(() => {
29
- const anchor = props.anchor;
32
if (!anchor) return;
33
34
const updatePosition = () => {
@@ -47,10 +49,15 @@ export function ComposerCommandMenuLayer(props: {
49
return;
50
}
51
const composerOverlap = rootFontSizePx + 1;
52
+ const spaceAbove = rect.top + composerOverlap;
53
+ const bottom = window.innerHeight - spaceAbove;
54
+ const floorHeight = Math.max(96, spaceAbove - 24);
55
+ const maxHeight = canOverflowTop ? floorHeight : Math.min(floorHeight, window.innerHeight);
56
const next = {
51
- bottom: window.innerHeight - rect.top - composerOverlap,
57
+ // With too little room above, the menu slides down over the composer instead of past the window top.
58
+ bottom: canOverflowTop ? bottom : Math.min(bottom, window.innerHeight - maxHeight),
59
left: rect.left + drawerInset,
53
- maxHeight: Math.max(96, rect.top - 24 + composerOverlap),
60
+ maxHeight,
61
width,
62
};
63
setPosition((current) =>
@@ -73,9 +80,9 @@ export function ComposerCommandMenuLayer(props: {
80
window.removeEventListener("resize", updatePosition);
81
window.removeEventListener("scroll", updatePosition, true);
82
};
76
- }, [props.anchor]);
83
+ }, [anchor, canOverflowTop]);
84
78
- if (!props.anchor || !position) return null;
85
+ if (!anchor || !position) return null;
86
87
return createPortal(
88
<div
apps/web/src/components/ui/autocomplete.tsx
+2
-1
@@ -193,7 +193,8 @@ function AutocompleteEmpty({ className, ...props }: AutocompletePrimitive.Empty.
193
194
function AutocompleteList({ className, ...props }: AutocompletePrimitive.List.Props) {
195
return (
196
- <ScrollArea scrollbarGutter scrollFade>
196
+ // A flex column lets the viewport shrink with a height-capped parent instead of overflowing it.
197
+ <ScrollArea className="flex flex-col" scrollbarGutter scrollFade>
198
<AutocompletePrimitive.List
199
className={cn("not-empty:scroll-py-1 not-empty:p-1", className)}
200
data-slot="autocomplete-list"
scripts/scenarios/composer-menu.ts
new
+105
@@ -0,0 +1,105 @@
1
+/// <reference lib="dom" />
2
+// Helpers for composer suggestion scenarios in short windows; the DOM lib types their page code.
3
+import type { Browser } from "@e2e-dev/web";
4
+import { expect, type Screen } from "e2e";
5
+
6
+import type { T3 } from "./t3.ts";
7
+
8
+const FILE_NAMES = Array.from(
9
+ { length: 40 },
10
+ (_, index) => `entry-${String(index + 1).padStart(2, "0")}.ts`,
11
+);
12
+
13
+/** Seeds a project with enough files to overflow the menu and opens a thread in it. */
14
+export async function openThreadWithManyFiles(t3: T3) {
15
+ const files = Object.fromEntries(FILE_NAMES.map((name) => [`src/${name}`, `export {};\n`]));
16
+ const project = await t3.project("demo", files);
17
+ const thread = await t3.thread({ project, title: "Short window", messages: ["hello"] });
18
+ await t3.open(thread);
19
+}
20
+
21
+/** Types a fourteen-line draft, then opens the `@` file suggestions at its end. */
22
+export async function openFileSuggestionsUnderTallDraft(browser: Browser, screen: Screen) {
23
+ // A phone-width window collapses the composer until it is tapped.
24
+ await screen.getByRole("button", "Expand composer").tap();
25
+ await screen.getByRole("textbox").tap();
26
+ for (let line = 1; line <= 14; line += 1) {
27
+ await browser.keyboard.type(`line ${line}`);
28
+ if (line < 14) await browser.keyboard.press("Shift+Enter");
29
+ }
30
+ await browser.keyboard.press("Control+End");
31
+ await browser.keyboard.type(" @");
32
+ await expect
33
+ .poll(() =>
34
+ browser.evaluate(
35
+ () => document.querySelectorAll('[data-composer-command-drawer] [role="option"]').length,
36
+ ),
37
+ )
38
+ .toBeGreaterThan(FILE_NAMES.length);
39
+}
40
+
41
+/** Wheels the suggestions from a point inside the visible drawer until they reach that end. */
42
+export async function wheelSuggestions(browser: Browser, direction: "up" | "down") {
43
+ const point = await browser.evaluate(() => {
44
+ const layer = document.querySelector('[data-composer-drawer-layer="true"]');
45
+ if (!layer) return null;
46
+ const rect = layer.getBoundingClientRect();
47
+ const top = Math.max(rect.top, 0);
48
+ const bottom = Math.min(rect.bottom, window.innerHeight);
49
+ return { x: rect.left + rect.width / 2, y: top + (bottom - top) / 3 };
50
+ });
51
+ expect(point).not.toBeNull();
52
+ await browser.mouse.move(point!.x, point!.y);
53
+ // Wheel scrolling lands a frame or more later, so keep wheeling until the list is at its end.
54
+ await expect
55
+ .poll(async () => {
56
+ await browser.mouse.wheel(0, direction === "down" ? 4000 : -4000);
57
+ return browser.evaluate((direction) => {
58
+ const viewport = document.querySelector(
59
+ '[data-composer-command-drawer] [data-slot="scroll-area-viewport"]',
60
+ );
61
+ if (!viewport) return false;
62
+ return direction === "down"
63
+ ? viewport.scrollTop >= viewport.scrollHeight - viewport.clientHeight - 1
64
+ : viewport.scrollTop <= 0;
65
+ }, direction);
66
+ })
67
+ .toBe(true);
68
+}
69
+
70
+/**
71
+ * The first suggestion or last file row, and its center when the whole row is visible
72
+ * and a click there lands on it, otherwise `null`.
73
+ */
74
+export const findHittableRow = (browser: Browser, which: "first" | "last-file") =>
75
+ browser.evaluate(
76
+ ({ which, names }) => {
77
+ const options = [
78
+ ...document.querySelectorAll<HTMLElement>('[data-composer-command-drawer] [role="option"]'),
79
+ ];
80
+ const row =
81
+ which === "first"
82
+ ? options[0]
83
+ : options.findLast((option) =>
84
+ names.some((name) => option.textContent?.startsWith(name)),
85
+ );
86
+ if (!row) return { label: null, point: null };
87
+ const text = row.textContent ?? "";
88
+ const label = names.find((name) => text.startsWith(name)) ?? text;
89
+ const rect = row.getBoundingClientRect();
90
+ const viewport = row.closest('[data-slot="scroll-area-viewport"]')?.getBoundingClientRect();
91
+ const top = Math.max(0, viewport?.top ?? 0);
92
+ const bottom = Math.min(window.innerHeight, viewport?.bottom ?? window.innerHeight);
93
+ if (rect.top < top - 1 || rect.bottom > bottom + 1) return { label, point: null };
94
+ const point = { x: rect.left + rect.width / 2, y: rect.top + rect.height / 2 };
95
+ const hit = document.elementFromPoint(point.x, point.y)?.closest('[role="option"]') === row;
96
+ return { label, point: hit ? point : null };
97
+ },
98
+ { which, names: [...FILE_NAMES, "README.md"] },
99
+ );
100
+
101
+export async function clickAt(browser: Browser, point: { readonly x: number; readonly y: number }) {
102
+ await browser.mouse.move(point.x, point.y);
103
+ await browser.mouse.down();
104
+ await browser.mouse.up();
105
+}
scripts/scenarios/short-window-file-suggestions-reach-last-file.e2e.ts
new
+29
@@ -0,0 +1,29 @@
1
+import { expect } from "e2e";
2
+
3
+import {
4
+ clickAt,
5
+ findHittableRow,
6
+ openFileSuggestionsUnderTallDraft,
7
+ openThreadWithManyFiles,
8
+ wheelSuggestions,
9
+} from "./composer-menu.ts";
10
+import { test, WEB } from "./t3.ts";
11
+
12
+test(
13
+ "In a short window, file suggestions wheel down to a last file the pointer can pick",
14
+ WEB,
15
+ async ({ t3, app, browser, screen }) => {
16
+ await browser.setViewport({ width: 375, height: 500 });
17
+ await openThreadWithManyFiles(t3);
18
+ await openFileSuggestionsUnderTallDraft(browser, screen);
19
+
20
+ await wheelSuggestions(browser, "down");
21
+ await app.screenshot("scrolled-to-bottom");
22
+ const last = await findHittableRow(browser, "last-file");
23
+ expect(last.label).toBe("README.md");
24
+ expect(last.point).not.toBeNull();
25
+
26
+ await clickAt(browser, last.point!);
27
+ await expect(screen.getByRole("textbox")).toContainText("README.md");
28
+ },
29
+);
scripts/scenarios/shrunk-window-file-suggestions-reach-first-file.e2e.ts
new
+32
@@ -0,0 +1,32 @@
1
+import { expect } from "e2e";
2
+
3
+import {
4
+ clickAt,
5
+ findHittableRow,
6
+ openFileSuggestionsUnderTallDraft,
7
+ openThreadWithManyFiles,
8
+ wheelSuggestions,
9
+} from "./composer-menu.ts";
10
+import { test, WEB } from "./t3.ts";
11
+
12
+test(
13
+ "After the window shrinks, file suggestions wheel up to a first suggestion the pointer can pick",
14
+ WEB,
15
+ async ({ t3, app, browser, screen }) => {
16
+ await browser.setViewport({ width: 375, height: 500 });
17
+ await openThreadWithManyFiles(t3);
18
+ await openFileSuggestionsUnderTallDraft(browser, screen);
19
+ await browser.keyboard.press("Escape");
20
+ await browser.keyboard.press("Backspace");
21
+ await browser.keyboard.type("@");
22
+
23
+ await browser.setViewport({ width: 375, height: 300 });
24
+ await wheelSuggestions(browser, "up");
25
+ await app.screenshot("scrolled-to-top");
26
+ const first = await findHittableRow(browser, "first");
27
+ expect(first.point).not.toBeNull();
28
+
29
+ await clickAt(browser, first.point!);
30
+ await expect(screen.getByRole("textbox")).toContainText(first.label!);
31
+ },
32
+);