Skip to content

Commit 433bff1

Browse files
fix(web): clicking a file in the Files tree keeps focus on that row (#28521)
1 parent 625b9ac commit 433bff1

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,29 @@ describe("workspace area focus", () => {
226226
await vi.waitFor(() => expect(document.activeElement).toBe(composer.button));
227227
});
228228

229+
it("keeps focus on the control a panel tab switch came from", () => {
230+
using fixture = setup();
231+
const panel = fixture.area("panel", 3);
232+
const content = document.createElement("div");
233+
content.setAttribute("data-right-panel-surface-content", "");
234+
const row = (name: string) => {
235+
const button = document.createElement("button");
236+
button.textContent = name;
237+
content.append(button);
238+
return button;
239+
};
240+
const earlierRow = row("reference-analysis.md");
241+
const clickedRow = row("print-guide.md");
242+
panel.element.append(content);
243+
panel.element.dataset.workspaceFocusKey = "panel:file:print-guide.md";
244+
earlierRow.focus();
245+
panel.element.dataset.workspaceFocusKey = "panel:file:reference-analysis.md";
246+
clickedRow.focus();
247+
panel.element.dataset.workspaceFocusKey = "panel:file:print-guide.md";
248+
expect(fixture.controller.focus("panel")).toBe(true);
249+
expect(document.activeElement).toBe(clickedRow);
250+
});
251+
229252
it("waits for a requested area to mount", async () => {
230253
using fixture = setup();
231254
fixture.area("composer", 2);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ export function createWorkspaceFocusController(doc: Document) {
186186
// A lazy surface's Suspense fallback is empty. Wait for its content instead
187187
// of claiming focus on the tab strip before the useful controls mount.
188188
if (surface && !surface.hasChildNodes()) return false;
189+
if (!selector && surface?.contains(doc.activeElement)) return true;
189190
if (selector) {
190191
const target = area.querySelector<HTMLElement>(selector);
191192
if (!target || !isWorkspaceElementVisible(target)) return false;

0 commit comments

Comments
 (0)