@devries-cameron20 / t3code-1 / commits / 69dd6956d5
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): return focus to composer after timeline prompts (#33192)

Yash Singh committed Nov 8, 2026 at 23:16 UTC 69dd6956d579b2313b3741512c80da366b91e57c
2 files changed +27 -13
apps/web/src/lib/workspaceFocus.browser.test.ts
+16 -8
@@ -206,15 +206,23 @@ describe("workspace area focus", () => {
206 expect(timeline.scrollTop).toBe(300);
207 });
208
209 - it("returns focus to the area when its focused control disappears", async () => {
209 + it.each([
210 + ["panel", "panel", "removed"],
211 + ["conversation", "composer", "removed"],
212 + ["conversation", "composer", "disabled"],
213 + ])("recovers focus from a %s control to the %s when %s", async (source, destination, change) => {
214 using fixture = setup();
211 - const panel = fixture.area("panel", 3);
212 - const tab = document.createElement("button");
213 - tab.textContent = "Files tab";
214 - panel.element.append(tab);
215 - tab.focus();
216 - tab.remove();
217 - await vi.waitFor(() => expect(document.activeElement).toBe(panel.button));
215 + const composer = fixture.area("composer", 2);
216 + const area = fixture.area(source, 3);
217 + const control = document.createElement("button");
218 + control.id = "pending-request";
219 + control.textContent = "Submit";
220 + area.element.append(control);
221 + control.focus();
222 + if (change === "disabled") control.disabled = true;
223 + else control.remove();
224 + const expected = destination === "composer" ? composer.button : area.button;
225 + await vi.waitFor(() => expect(document.activeElement).toBe(expected));
226 });
227
228 it("falls back to the main content when the whole area disappears", async () => {
apps/web/src/lib/workspaceFocus.ts
+11 -5
@@ -240,25 +240,31 @@ export function createWorkspaceFocusController(doc: Document) {
240 return focusArea(area);
241 };
242
243 - // Focus that drops to the body because its element was hidden, made inert, or removed
244 - // returns to the same control when React remounted it, else to its area, else the content.
243 + // Focus that drops to the body because its element was hidden, made inert, disabled, or removed
244 + // returns to a remounted control, else its area, or the composer for a finished timeline prompt.
245 const recover = (event: FocusEvent) => {
246 const lost = event.target;
247 if (!(lost instanceof HTMLElement) || event.relatedTarget) return;
248 const areaName = workspaceArea(lost)?.dataset.workspaceArea;
249 + const recoveryArea = areaName === "conversation" ? "composer" : areaName;
250 const label = lost.getAttribute("aria-label");
251 requestAnimationFrame(() => {
251 - if (doc.activeElement !== doc.body || !doc.hasFocus() || isWorkspaceElementVisible(lost))
252 + if (
253 + doc.activeElement !== doc.body ||
254 + !doc.hasFocus() ||
255 + (isWorkspaceElementVisible(lost) && !lost.matches(":disabled"))
256 + )
257 return;
258 const remounted = Array.from(doc.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR)).find(
259 (element) =>
260 element.tagName === lost.tagName &&
261 ((lost.id && element.id === lost.id) ||
262 (label && element.getAttribute("aria-label") === label)) &&
258 - isWorkspaceElementVisible(element),
263 + isWorkspaceElementVisible(element) &&
264 + !element.matches(":disabled"),
265 );
266 if (remounted) remounted.focus({ preventScroll: true });
261 - else if (!areaName || !focus(areaName)) focus("content");
267 + else if (!recoveryArea || !focus(recoveryArea)) focus("content");
268 });
269 };
270 doc.addEventListener("focusout", recover);