Skip to content

Commit 50549f7

Browse files
committed
fix(web): Enter selects the first matching ref in Diff panel base-ref picker
Enable autoHighlight on the Diff panel base-ref Combobox so typing a search query highlights the first matching ref and pressing Enter selects it instead of closing the picker with the previous base ref unchanged.
1 parent 0f7ae4e commit 50549f7

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

‎apps/web/src/components/DiffPanel.browser.test.tsx‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,3 +607,27 @@ it("filters base-ref dropdown rows against the search query", async () => {
607607
await expect.element(mainOption).toBeVisible();
608608
await expect.element(remoteOption).toBeVisible();
609609
});
610+
611+
it("selects the first matching base ref on Enter after searching", async () => {
612+
using context = setup("origin/orphan");
613+
useDiffPanelStore.getState().selectBranchBaseRef(context.threadRef, "main");
614+
await using screen = await render(
615+
<RegistryContext.Provider value={context.registry}>
616+
<DiffPanel composerDraftTarget={context.threadRef} workspaceMutationId={null} visible />
617+
</RegistryContext.Provider>,
618+
);
619+
await userEvent.click(screen.getByRole("combobox", { name: /Change comparison target/ }));
620+
const searchInput = page.getByPlaceholder("Search refs...");
621+
await userEvent.type(searchInput, "orphan");
622+
await expect.element(page.getByRole("option", { name: /origin\/orphan/ })).toBeVisible();
623+
await userEvent.keyboard("{Enter}");
624+
await expect.element(searchInput).not.toBeInTheDocument();
625+
const key = scopedThreadKey(context.threadRef);
626+
await vi.waitFor(() => {
627+
expect(useDiffPanelStore.getState().byThreadKey[key]).toEqual({
628+
kind: "branch",
629+
baseRef: "origin/orphan",
630+
});
631+
expect(useDiffPanelStore.getState().branchBaseRefByThreadKey[key]).toBe("origin/orphan");
632+
});
633+
});

‎apps/web/src/components/DiffPanel.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,7 @@ export default function DiffPanel({
13511351
if (!value) return;
13521352
selectBranchBaseRef(value === AUTOMATIC_BASE_REF ? null : value);
13531353
}}
1354+
autoHighlight
13541355
>
13551356
<ComboboxTrigger
13561357
render={<Button variant="ghost-muted" size="xs" />}

0 commit comments

Comments
 (0)