Skip to content
Open
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
25 changes: 25 additions & 0 deletions apps/web/src/components/ChatView.logic.browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,31 @@ it("keeps focus in a region with its own keys on window return", async () => {
);
});

it("keeps focus on a trigger whose menu just opened on window return", () => {
const trigger = document.createElement("button");
trigger.setAttribute("aria-haspopup", "menu");
trigger.setAttribute("aria-expanded", "true");
const disclosure = document.createElement("button");
disclosure.setAttribute("aria-expanded", "true");
document.body.append(trigger, disclosure);
using _buttons = {
[Symbol.dispose]: () => {
trigger.remove();
disclosure.remove();
},
};

trigger.focus();
expect(shouldRefocusComposerOnWindowFocus(document.activeElement, null)).toBe(false);
trigger.setAttribute("aria-expanded", "false");
expect(shouldRefocusComposerOnWindowFocus(document.activeElement, null)).toBe(true);
disclosure.focus();
expect(
shouldRefocusComposerOnWindowFocus(document.activeElement, null),
"an expanded fold or folder toggle opens no popup",
).toBe(true);
});

it("refocuses the composer on window return from a clicked area after a bare key press", async () => {
const controller = createWorkspaceFocusController(document);
const root = document.createElement("div");
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/ChatView.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ export function shouldRefocusComposerOnWindowFocus(
}
return (
activeElement.closest(
'[data-workspace-keyboard-focus], [data-sidebar-row]:focus-visible, [role="dialog"], [role="alertdialog"], [role="application"], [role="menu"], [role="listbox"], [data-slot$="-popup"], [data-terminal-owner], [aria-keyshortcuts]',
'[data-workspace-keyboard-focus], [data-sidebar-row]:focus-visible, [role="dialog"], [role="alertdialog"], [role="application"], [role="menu"], [role="listbox"], [data-slot$="-popup"], [data-terminal-owner], [aria-keyshortcuts], [aria-haspopup][aria-expanded="true"]',
) === null
);
}
Expand Down
Loading