Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions apps/web/src/lib/workspaceFocus.browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,29 @@ describe("workspace area focus", () => {
await vi.waitFor(() => expect(document.activeElement).toBe(composer.button));
});

it("keeps focus on the control a panel tab switch came from", () => {
using fixture = setup();
const panel = fixture.area("panel", 3);
const content = document.createElement("div");
content.setAttribute("data-right-panel-surface-content", "");
const row = (name: string) => {
const button = document.createElement("button");
button.textContent = name;
content.append(button);
return button;
};
const earlierRow = row("reference-analysis.md");
const clickedRow = row("print-guide.md");
panel.element.append(content);
panel.element.dataset.workspaceFocusKey = "panel:file:print-guide.md";
earlierRow.focus();
panel.element.dataset.workspaceFocusKey = "panel:file:reference-analysis.md";
clickedRow.focus();
panel.element.dataset.workspaceFocusKey = "panel:file:print-guide.md";
expect(fixture.controller.focus("panel")).toBe(true);
expect(document.activeElement).toBe(clickedRow);
});

it("waits for a requested area to mount", async () => {
using fixture = setup();
fixture.area("composer", 2);
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/lib/workspaceFocus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export function createWorkspaceFocusController(doc: Document) {
// A lazy surface's Suspense fallback is empty. Wait for its content instead
// of claiming focus on the tab strip before the useful controls mount.
if (surface && !surface.hasChildNodes()) return false;
if (!selector && surface?.contains(doc.activeElement)) return true;
if (selector) {
const target = area.querySelector<HTMLElement>(selector);
if (!target || !isWorkspaceElementVisible(target)) return false;
Expand Down
Loading