Skip to content

Commit ad13185

Browse files
committed
Keep search focus and simplify page navigation checks
Signed-off-by: Codex <[email protected]>
1 parent b4c7b91 commit ad13185

3 files changed

Lines changed: 51 additions & 19 deletions

File tree

‎src/app/shell/PageSearch.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,10 @@ export function PageSearch({
199199
? currentTarget.channelId
200200
: undefined
201201
}
202-
onScopeChange={(channelId) => setScopedChannelId(channelId)}
202+
onScopeChange={(channelId) => {
203+
setScopedChannelId(channelId);
204+
input.current?.focus();
205+
}}
203206
close={() => {
204207
returnFocus.current = document.getElementById("main-content");
205208
setSearchOpen(false);

‎tests/browser/global-search.spec.mjs‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,43 @@ test("search arrows traverse the conversation action and recent activity, Enter
100100
).toBeVisible();
101101
});
102102

103+
test("changing search scope returns focus to the input without clearing the query", async ({
104+
page,
105+
app,
106+
}) => {
107+
await page.goto(app.origin);
108+
await button(page, "Search Buzz").click();
109+
const scopeAction = page
110+
.getByRole("dialog", { name: "Search Buzz" })
111+
.getByRole("group", { name: "This conversation" })
112+
.getByRole("option");
113+
await scopeAction.click();
114+
115+
const scoped = page.getByRole("dialog", { name: "Search this conversation" });
116+
const scopedInput = scoped.getByRole("combobox", {
117+
name: "Search this conversation",
118+
});
119+
await expect(scopedInput).toBeFocused();
120+
await page.keyboard.type("hello");
121+
await expect(scopedInput).toHaveValue("hello");
122+
123+
const chip = scoped.getByRole("button", {
124+
name: /Remove .* search scope/,
125+
});
126+
await chip.focus();
127+
await chip.press("Enter");
128+
const global = page.getByRole("dialog", { name: "Search Buzz" });
129+
const input = global.getByRole("combobox", { name: "Search Buzz" });
130+
await expect(input).toBeFocused();
131+
await expect(input).toHaveValue("hello");
132+
await page.keyboard.press("ArrowDown");
133+
await expect(
134+
global
135+
.getByRole("group", { name: "This conversation" })
136+
.getByRole("option"),
137+
).toHaveAttribute("aria-selected", "true");
138+
});
139+
103140
// Real portal → routed timeline/thread ownership and focus, in both browser engines.
104141
test.describe("public search destination", () => {
105142
test.use({ openSearch: true, productionBroker: true });

‎tests/browser/navigation.mjs‎

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,15 @@ export async function pageChoices(page) {
88
}
99

1010
export async function openPage(page, name) {
11-
await pageChoices(page);
11+
// The community rail appears after local startup has replaced the launch view.
12+
await expect(
13+
page.getByRole("button", { name: "Switch to Primary", exact: true }),
14+
).toBeVisible();
15+
const choices = await pageChoices(page);
1216
const dialog = page.getByRole("dialog", { name: "Search Buzz", exact: true });
13-
const input = dialog.getByRole("combobox", { name: "Search Buzz" });
14-
const choice = dialog
15-
.getByRole("group", { name: "Pages", exact: true })
16-
.getByRole("option", { name, exact: true });
17-
// Startup may replace the search state while the first community route settles.
18-
for (let attempt = 0; attempt < 3; attempt++) {
19-
await input.fill(name);
20-
try {
21-
await choice.click({ timeout: 3000 });
22-
await expect(dialog).not.toBeVisible({ timeout: 1000 });
23-
return;
24-
} catch (error) {
25-
// Navigation can finish while Playwright is still waiting for a replaced option.
26-
if (!(await dialog.isVisible())) return;
27-
if (attempt === 2) throw error;
28-
}
29-
}
17+
const choice = choices.getByRole("option", { name, exact: true });
18+
// Registered page actions are visible only after the plugin catalog is ready.
19+
await expect(choice).toBeVisible();
20+
await choice.click();
21+
await expect(dialog).not.toBeVisible();
3022
}

0 commit comments

Comments
 (0)