Skip to content

Commit f5adff2

Browse files
committed
fix(web): picking a sidebar search result scrolls the list to that thread
A mouse pick focused the result, so closing the results dropped focus and its recovery scrolled the list back to the previous thread. The result now keeps focus in the search box, as Enter does. Card rows without a meta line hinted 2px short of their rendered height, so the reveal into the just-mounted list landed 2px short per row above the thread and could leave it below the fold.
1 parent 08a463e commit f5adff2

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { describe, expect, it, vi } from "vite-plus/test";
2+
import { userEvent } from "vite-plus/test/browser";
3+
4+
import { render } from "../../../test/render";
5+
import { makeThreadFixture } from "../../test-fixtures";
6+
import { SidebarSearchResultRow } from "./SidebarThreadRow";
7+
8+
describe("SidebarSearchResultRow", () => {
9+
it("leaves focus in the search box when a click picks the result", async () => {
10+
const onSelect = vi.fn();
11+
await using screen = await render(
12+
<>
13+
<input aria-label="Search threads" />
14+
<ul role="listbox">
15+
<SidebarSearchResultRow
16+
isSettled={false}
17+
thread={makeThreadFixture({ title: "Invoice export" })}
18+
project={null}
19+
projectDisplayName={null}
20+
environmentLabel={null}
21+
environmentMachine="server"
22+
providerEntryByInstanceId={new Map()}
23+
isHighlighted={false}
24+
isRouteActive={false}
25+
resultId="result-0"
26+
searchMatch={null}
27+
searchQuery="invoice"
28+
onHighlight={() => {}}
29+
onSelect={onSelect}
30+
onFileDropThreads={() => {}}
31+
/>
32+
</ul>
33+
</>,
34+
);
35+
const search = screen.getByRole("textbox", { name: "Search threads" });
36+
await userEvent.click(search);
37+
38+
await userEvent.click(screen.getByRole("option"));
39+
40+
expect(onSelect).toHaveBeenCalledOnce();
41+
// Picking clears the results; a focused result would drop focus for recovery to place.
42+
await expect.element(search).toHaveFocus();
43+
});
44+
});

‎apps/web/src/components/sidebar/SidebarThreadRow.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1385,9 +1385,11 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
13851385
data-thread-item={threadKey}
13861386
{...sortableRootProps}
13871387
{...(fileDropHandlers ?? {})}
1388+
// The hints are the rendered heights inside py-0.5. Revealing the open thread measures rows
1389+
// that have not rendered yet, so a hint off by a pixel lands it a pixel short per row above.
13881390
className={cn(
13891391
"list-none py-0.5 [content-visibility:auto] [contain-intrinsic-size:auto_78px]",
1390-
metaLineEmpty && "[contain-intrinsic-size:auto_58px]",
1392+
metaLineEmpty && "[contain-intrinsic-size:auto_60px]",
13911393
sortable?.isDragging && "relative z-20",
13921394
)}
13931395
>
@@ -1691,6 +1693,9 @@ export const SidebarSearchResultRow = memo(function SidebarSearchResultRow(props
16911693
aria-describedby={`${props.resultId}-pr`}
16921694
aria-label={accessibility.label}
16931695
onMouseMove={props.onHighlight}
1696+
// Focus stays in the search box, as for Enter. A focused result would lose focus as
1697+
// the results close, and its recovery scrolls the list away from the opened thread.
1698+
onPointerDown={(event) => event.preventDefault()}
16941699
onClick={props.onSelect}
16951700
className={cn(
16961701
"group/sidebar-row group/v2-row flex min-h-9 w-full cursor-pointer items-center gap-2.5 rounded-md px-2.5 py-1 text-left text-sm outline-none",

0 commit comments

Comments
 (0)