Fix two model picker bugs that lost a click or an Enter (#10962)

* fix(app): keep a pressed model row under the pointer

Pressing a model row focuses it. The row's focus handler marked it as the
keyboard-active row, and the list then scrolled that row into view. When
the list had not yet reported which rows it shows, as on a slow machine
right after a provider opens, it centered the row. The row moved before
the button came up, and the click selected nothing.

Only keyboard focus (:focus-visible on web) now marks a row active, so a
press never scrolls the list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(app): keep model search focused when the model list scrolls on web

React Native Web blurs the focused input on every scroll when
keyboardDismissMode is on-drag. The reveal scroll after ArrowDown, or a
wheel scroll, moved focus out of the search field, and the sheet focus
trap put it on the Back button, so Enter went back instead of selecting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit e6f0ad272d)
This commit is contained in:
paseo-bot[bot]
2026-11-27 02:56:07 +01:00
committed by Mohamed Boudra
parent 2f54a1d750
commit edd526561f
5 changed files with 84 additions and 5 deletions
@@ -3,7 +3,9 @@ import type { DaemonClient } from "@getpaseo/client/internal/daemon-client";
import { test, expect, type Page } from "../support/fixtures";
import { connectDaemonClient } from "../support/helpers/daemon-client-loader";
import {
clickModelRowWhileProviderOpens,
closeModelPicker,
expectModelListScrollKeepsSearchFocused,
expectModelSearchEmptyState,
expectModelPickerHeight,
expectModelPickerWidth,
@@ -227,6 +229,7 @@ test.describe("Cross-provider model search", () => {
await page.keyboard.press("Enter");
const deepRow = viewport.getByTestId(`model-row-${STUDIO.id}-studio-deep`);
await expect(deepRow).toBeVisible();
await expectModelListScrollKeepsSearchFocused(page);
for (let step = 0; step < 5; step += 1) {
if ((await deepRow.getAttribute("data-active")) === "true") break;
@@ -257,6 +260,16 @@ test.describe("Cross-provider model search", () => {
await expect(trigger).toContainText("Ten second stream");
});
await test.step("a press on a model row selects it while the provider list is still opening", async () => {
await openModelPicker(page);
await clickModelRowWhileProviderOpens(page, {
provider: "mock",
modelLabel: "One minute stream",
});
await expect(viewport).toHaveCount(0);
await expect(trigger).toContainText("One minute stream");
});
await test.step("Enter on the active profile row applies it", async () => {
await openModelPicker(page);
await expect(profileRow).toHaveAttribute("data-active", "true");
@@ -768,6 +768,44 @@ export async function selectModelRow(
await modelRow(page, input).click();
}
/**
* Opens a provider on a slow machine and clicks a model row before the list has
* finished laying out, holding the button as long as a person does.
*/
export async function clickModelRowWhileProviderOpens(
page: Page,
input: { provider: string; modelLabel: string },
): Promise<void> {
const viewport = pickerViewport(page);
await drillIntoProvider(page, input.provider);
const rowBox = await viewport.getByText(input.modelLabel, { exact: true }).boundingBox();
if (!rowBox) throw new Error(`Model row ${input.modelLabel} has no box`);
await viewport.getByRole("button", { name: "Back", exact: true }).click();
const cdp = await page.context().newCDPSession(page);
await cdp.send("Emulation.setCPUThrottlingRate", { rate: 10 });
try {
await drillIntoProvider(page, input.provider);
await page.mouse.click(rowBox.x + rowBox.width / 2, rowBox.y + rowBox.height / 2, {
delay: 150,
});
} finally {
await cdp.send("Emulation.setCPUThrottlingRate", { rate: 1 });
await cdp.detach();
}
}
/** Scrolling a provider's model list with the wheel leaves typing and Enter in the search field. */
export async function expectModelListScrollKeepsSearchFocused(page: Page): Promise<void> {
const search = pickerViewport(page).getByTestId("model-search-input");
const list = pickerViewport(page).getByTestId("compact-model-list");
await expect(search).toBeFocused();
await list.hover();
await page.mouse.wheel(0, 200);
await expect.poll(() => list.evaluate((element) => element.scrollTop)).toBeGreaterThan(0);
await expect(search).toBeFocused();
}
// ─── Cross-provider model search ───────────────────────────────────────────
export async function searchAllModels(page: Page, query: string): Promise<void> {
@@ -2,3 +2,8 @@
export function focusedModelBrowserControlOwnsEnter(): boolean {
return false;
}
/** Native fires focus on rows only for a hardware keyboard or a TV remote. */
export function focusCameFromKeyboard(_target: unknown): boolean {
return true;
}
@@ -13,3 +13,11 @@ export function focusedModelBrowserControlOwnsEnter(): boolean {
if (active.closest('[data-model-browser-row="true"]')) return false;
return active.matches(ACTIVATES_ON_ENTER);
}
/**
* A pointer press also focuses the row it lands on. Only keyboard focus marks a row
* active, so the press does not scroll the list to that row before the button is released.
*/
export function focusCameFromKeyboard(target: unknown): boolean {
return target instanceof Element && target.matches(":focus-visible");
}
+20 -5
View File
@@ -18,6 +18,7 @@ import {
Text,
View,
type AccessibilityActionEvent,
type FocusEvent,
type GestureResponderEvent,
type LayoutChangeEvent,
type NativeScrollEvent,
@@ -75,7 +76,10 @@ import {
import { useProviderSettingsStore } from "@/stores/provider-settings-store";
import { useCurrentOverlayLayer } from "@/lib/overlay-root";
import { ICON_SIZE, type Theme } from "@/styles/theme";
import { focusedModelBrowserControlOwnsEnter } from "@/components/model-browser-focus";
import {
focusCameFromKeyboard,
focusedModelBrowserControlOwnsEnter,
} from "@/components/model-browser-focus";
import {
MODEL_BROWSER_CREATE_PROFILE_KEY,
MODEL_BROWSER_KEYBOARD_KEYS,
@@ -630,6 +634,12 @@ function ModelBrowserPressable({
},
[onPress],
);
const handleFocus = useCallback(
(event: FocusEvent) => {
if (onFocus && focusCameFromKeyboard(event.target)) onFocus();
},
[onFocus],
);
const handleAccessibilityAction = useCallback(
(event: AccessibilityActionEvent) => {
if (event.nativeEvent.actionName === "activate") onPress();
@@ -651,7 +661,7 @@ function ModelBrowserPressable({
ref={rowRef}
onLayout={onLayout}
onPress={handlePress}
onFocus={onFocus}
onFocus={handleFocus}
hitSlop={hitSlop}
style={style}
accessibilityRole="button"
@@ -1428,7 +1438,7 @@ function IndependentModelList({
viewabilityConfig={reveal.viewabilityConfig}
style={styles.virtualizedModelList}
keyboardShouldPersistTaps="handled"
keyboardDismissMode="on-drag"
keyboardDismissMode={MODEL_LIST_KEYBOARD_DISMISS_MODE}
showsVerticalScrollIndicator={false}
contentContainerStyle={styles.virtualizedModelListContent}
nestedScrollEnabled
@@ -1466,7 +1476,7 @@ function IndependentProviderList({
onScroll={onScroll}
scrollEventThrottle={16}
keyboardShouldPersistTaps="handled"
keyboardDismissMode="on-drag"
keyboardDismissMode={MODEL_LIST_KEYBOARD_DISMISS_MODE}
showsVerticalScrollIndicator={false}
nestedScrollEnabled
testID="compact-provider-list"
@@ -1618,6 +1628,11 @@ function ModelSearchEmptyState() {
);
}
// React Native Web blurs the focused input on every scroll in "on-drag" mode, including wheel
// scrolls and the scroll that reveals an arrowed-to row. That moves focus out of search, so
// typing stops and Enter lands on the header's Back button. Only a native keyboard needs it.
const MODEL_LIST_KEYBOARD_DISMISS_MODE = isNative ? "on-drag" : "none";
interface ModelBrowserKeyboardBinding {
view: ModelBrowserView;
navItems: readonly ModelBrowserNavItem[];
@@ -1782,7 +1797,7 @@ function ModelBrowserBrowseView({
onScroll={browseReveal.onScroll}
scrollEventThrottle={16}
keyboardShouldPersistTaps="handled"
keyboardDismissMode="on-drag"
keyboardDismissMode={MODEL_LIST_KEYBOARD_DISMISS_MODE}
showsVerticalScrollIndicator={false}
testID="compact-provider-list"
>