Skip to content

Commit b10cdde

Browse files
darioielardiclaude
andauthored
fix(web): a new side chat focuses its message input (pingdotgg#32929)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 45e0143 commit b10cdde

2 files changed

Lines changed: 29 additions & 7 deletions

File tree

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,27 @@ describe("workspace area focus", () => {
259259
expect(document.activeElement).toBe(clickedRow);
260260
});
261261

262+
it("focuses a side chat's message input when the panel opens on it", () => {
263+
using fixture = setup();
264+
const panel = fixture.area("panel", 3);
265+
const content = document.createElement("div");
266+
content.setAttribute("data-right-panel-surface-content", "");
267+
const bringBack = document.createElement("button");
268+
bringBack.textContent = "Bring back";
269+
content.append(bringBack);
270+
panel.element.append(content);
271+
fixture.area("conversation", 1, content);
272+
const composer = fixture.area("composer", 2, content);
273+
const editor = document.createElement("div");
274+
editor.contentEditable = "true";
275+
composer.element.append(editor);
276+
expect(fixture.controller.focus("panel")).toBe(true);
277+
expect(document.activeElement).toBe(editor);
278+
// F6 from the message input moves on to the panel's own controls.
279+
expect(fixture.controller.move(1)).toBe(true);
280+
expect(document.activeElement).toBe(bringBack);
281+
});
282+
262283
it("waits for a requested area to mount", async () => {
263284
using fixture = setup();
264285
fixture.area("composer", 2);

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,19 @@ export function createWorkspaceFocusController(doc: Document) {
123123
};
124124
doc.addEventListener("focusin", remember);
125125

126-
const focusArea = (area: HTMLElement, restore = true) => {
126+
const focusArea = (area: HTMLElement, restore = true, nested = true) => {
127127
const key = area.dataset.workspaceFocusKey ?? area.dataset.workspaceArea!;
128128
const previous = restore ? lastFocused.get(key) : undefined;
129-
const belongs = (element: HTMLElement) =>
130-
workspaceArea(element) === area &&
131-
isWorkspaceElementVisible(element) &&
132-
!element.matches(":disabled");
129+
const usable = (element: HTMLElement) =>
130+
isWorkspaceElementVisible(element) && !element.matches(":disabled");
131+
const belongs = (element: HTMLElement) => workspaceArea(element) === area && usable(element);
132+
// A side chat's message input sits in its own area inside the panel. Opening the
133+
// panel focuses it, but F6 visits that area on its own, so it moves past it here.
133134
const preferred = Array.from(
134135
area.querySelectorAll<HTMLElement>(
135136
'[data-workspace-focus-default], [data-sidebar-row][aria-current="page"], [data-settings-section][tabindex="0"], .xterm-helper-textarea, [contenteditable="true"]',
136137
),
137-
).find(belongs);
138+
).find(nested ? usable : belongs);
138139
const fallback = Array.from(area.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR)).find(
139140
(element) => element.tabIndex >= 0 && belongs(element),
140141
);
@@ -257,7 +258,7 @@ export function createWorkspaceFocusController(doc: Document) {
257258
: areas.length - 1
258259
: (current + direction + areas.length) % areas.length;
259260
const area = areas[index]!;
260-
return focusArea(area);
261+
return focusArea(area, true, false);
261262
};
262263

263264
// Focus that drops to the body because its element was hidden, made inert, disabled, or removed

0 commit comments

Comments
 (0)