Skip to content

Commit f7e47fa

Browse files
darioielardiclaude
andcommitted
fix(web): a new side chat focuses its message input
Opening the right panel on a side chat put focus on its Bring back button. The panel's focus preference skipped the side chat's message input because it lives in a nested composer area. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent af65a55 commit f7e47fa

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎apps/web/src/lib/workspaceFocus.browser.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,24 @@ describe("workspace area focus", () => {
249249
expect(document.activeElement).toBe(clickedRow);
250250
});
251251

252+
it("focuses a side chat's message input when the panel opens on it", () => {
253+
using fixture = setup();
254+
const panel = fixture.area("panel", 3);
255+
const content = document.createElement("div");
256+
content.setAttribute("data-right-panel-surface-content", "");
257+
const bringBack = document.createElement("button");
258+
bringBack.textContent = "Bring back";
259+
content.append(bringBack);
260+
panel.element.append(content);
261+
fixture.area("conversation", 1, content);
262+
const composer = fixture.area("composer", 2, content);
263+
const editor = document.createElement("div");
264+
editor.contentEditable = "true";
265+
composer.element.append(editor);
266+
expect(fixture.controller.focus("panel")).toBe(true);
267+
expect(document.activeElement).toBe(editor);
268+
});
269+
252270
it("waits for a requested area to mount", async () => {
253271
using fixture = setup();
254272
fixture.area("composer", 2);

‎apps/web/src/lib/workspaceFocus.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,12 @@ export function createWorkspaceFocusController(doc: Document) {
112112
workspaceArea(element) === area &&
113113
isWorkspaceElementVisible(element) &&
114114
!element.matches(":disabled");
115+
// Nested areas count here: a side chat's message input sits in its own area inside the panel.
115116
const preferred = Array.from(
116117
area.querySelectorAll<HTMLElement>(
117118
'[data-workspace-focus-default], [data-sidebar-row][aria-current="page"], [data-settings-section][tabindex="0"], .xterm-helper-textarea, [contenteditable="true"]',
118119
),
119-
).find(belongs);
120+
).find((element) => isWorkspaceElementVisible(element) && !element.matches(":disabled"));
120121
const fallback = Array.from(area.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR)).find(
121122
(element) => element.tabIndex >= 0 && belongs(element),
122123
);

0 commit comments

Comments
 (0)