fix(search-tabs): select the right-hand neighbor when closing the active tab (#89)

This commit is contained in:
bookingseo 2026-07-19 12:14:43 +07:00 committed by GitHub
parent 01a97de55a
commit 57524b5b97
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 2 deletions

View File

@ -115,6 +115,10 @@ test.describe("Keyword Research navigation", () => {
await expect(
page.locator(`[data-search-tab-id="${closedTabId}"]`),
).toHaveCount(0);
await expect(page.getByRole("tab")).toHaveCount(2);
// Count only search tabs: the app shell has grown other tablists
// (Browse/Chat), so a bare role=tab count would include them.
await expect(
page.getByRole("tablist", { name: "Search tabs" }).getByRole("tab"),
).toHaveCount(2);
});
});

View File

@ -43,6 +43,7 @@ export function SearchTabStrip({
<div className="rounded-xl border border-base-300 bg-base-100 p-1">
<div
role="tablist"
aria-label="Search tabs"
className="flex min-w-0 items-stretch gap-1 overflow-x-auto"
>
{tabs.map((tab) => {

View File

@ -255,7 +255,11 @@ export function useSearchTabs(key: string) {
let activeTabId = current.activeTabId;
if (current.activeTabId === tabId) {
closedActive = true;
const neighbor = tabs[index - 1] ?? tabs[index] ?? null;
// Post-removal array: tabs[index] is the tab that slid into the
// closed tab's slot (its right-hand neighbor). Select it first —
// browser-tab convention and the documented e2e contract — and fall
// back to the left neighbor only when the last tab was closed.
const neighbor = tabs[index] ?? tabs[index - 1] ?? null;
activeTabId = neighbor?.id ?? null;
nextActiveTab = neighbor;
}