Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(web): focus model search when hovering an agent submenu (#6638)

Wolf Mermelstein847632f28595
diff --git a/apps/web/src/features/agents-view/views/AgentPicker.tsx b/apps/web/src/features/agents-view/views/AgentPicker.tsx
index bf1bb5b6a3..bac51c1cc8 100644
--- a/apps/web/src/features/agents-view/views/AgentPicker.tsx
+++ b/apps/web/src/features/agents-view/views/AgentPicker.tsx
@@ -221,6 +221,7 @@ function AgentPickerRow(props: {
<Dropdown.SubContent
aria-label={`Models for ${props.agent.name}`}
class="w-72 max-w-[calc(100vw-1rem)] max-h-[min(28rem,var(--kb-popper-content-available-height))] overflow-y-auto overscroll-contain"
+ onOpenAutoFocus={(event: Event) => event.preventDefault()}
onPointerDown={(event: PointerEvent) => event.stopPropagation()}
onMouseDown={(event: MouseEvent) => event.stopPropagation()}
>
@@ -247,6 +248,7 @@ function AgentModels(props: {
const defaultModel = () => props.agent.defaultModel ?? catalog.currentModel();
return (
<ModelCatalogMenu
+ autoFocusSearch
value={props.modelOverride ?? defaultModel() ?? null}
options={catalog.models().map((option) => ({
id: option.id,
diff --git a/apps/web/src/features/agents-view/views/NewChatPage.test.tsx b/apps/web/src/features/agents-view/views/NewChatPage.test.tsx
index a068d56bb1..bb4ac94c40 100644
--- a/apps/web/src/features/agents-view/views/NewChatPage.test.tsx
+++ b/apps/web/src/features/agents-view/views/NewChatPage.test.tsx
@@ -412,6 +412,20 @@ describe('agent-led new conversation', () => {
expect(row.textContent).toContain('Its runtime is disconnected');
});
+ it('focuses model search when hovering an agent submenu', async () => {
+ page();
+ await hoverAgent('Cursor');
+ const search = screen.getByRole('textbox', { name: 'Search models' });
+ await waitFor(() => expect(document.activeElement).toBe(search));
+
+ fireEvent.input(search, { target: { value: 'GPT' } });
+ expect((search as HTMLInputElement).value).toBe('GPT');
+ expect(screen.getByRole('menuitem', { name: /GPT-5/ })).toBeTruthy();
+ expect(
+ screen.queryByRole('menuitem', { name: /Cursor default/ })
+ ).toBeNull();
+ });
+
it('shows the model beside the agent and sends a hovered model choice only once', async () => {
const send = page();
expect(screen.getByRole('button', { name: 'Agent' }).textContent).toContain(
diff --git a/apps/web/src/lib/core/component/AI/component/input/ModelCatalogPicker.test.tsx b/apps/web/src/lib/core/component/AI/component/input/ModelCatalogPicker.test.tsx
index 61cbdc9b14..d29686b46c 100644
--- a/apps/web/src/lib/core/component/AI/component/input/ModelCatalogPicker.test.tsx
+++ b/apps/web/src/lib/core/component/AI/component/input/ModelCatalogPicker.test.tsx
@@ -11,7 +11,7 @@ import {
} from '@solidjs/testing-library';
import { createSignal, type JSX } from 'solid-js';
import { afterEach, describe, expect, it, vi } from 'vitest';
-import { ModelCatalogPicker } from './ModelCatalogPicker';
+import { ModelCatalogMenu, ModelCatalogPicker } from './ModelCatalogPicker';
import type { CatalogModelOption } from './modelCatalog';
const { isMobileWidth, setMobileWidth } = vi.hoisted(() => {
@@ -158,6 +158,48 @@ describe('ModelCatalogPicker search focus', () => {
});
});
+describe('ModelCatalogMenu search focus', () => {
+ it('puts caret in the search field when autoFocusSearch mounts the catalog', async () => {
+ render(() => (
+ <ModelCatalogMenu
+ autoFocusSearch
+ value="auto"
+ options={OPTIONS}
+ onSelect={() => {}}
+ />
+ ));
+ const search = screen.getByRole('textbox', { name: 'Search models' });
+ await waitFor(() => {
+ expect(document.activeElement).toBe(search);
+ });
+ });
+
+ it('reclaims search focus when the submenu trigger steals it', async () => {
+ render(() => (
+ <ModelCatalogMenu
+ autoFocusSearch
+ value="auto"
+ options={OPTIONS}
+ onSelect={() => {}}
+ />
+ ));
+ const search = screen.getByRole('textbox', { name: 'Search models' });
+ await waitFor(() => {
+ expect(document.activeElement).toBe(search);
+ });
+
+ const thief = document.createElement('button');
+ document.body.append(thief);
+ thief.focus();
+ expect(document.activeElement).toBe(thief);
+
+ await waitFor(() => {
+ expect(document.activeElement).toBe(search);
+ });
+ thief.remove();
+ });
+});
+
describe('ModelCatalogPicker more models at phone width', () => {
it('replaces the list in place and comes back', () => {
setMobileWidth(true);
diff --git a/apps/web/src/lib/core/component/AI/component/input/ModelCatalogPicker.tsx b/apps/web/src/lib/core/component/AI/component/input/ModelCatalogPicker.tsx
index 60ecb714f7..4e5890cc85 100644
--- a/apps/web/src/lib/core/component/AI/component/input/ModelCatalogPicker.tsx
+++ b/apps/web/src/lib/core/component/AI/component/input/ModelCatalogPicker.tsx
@@ -4,7 +4,15 @@ import CaretRight from '@phosphor/caret-right.svg';
import CheckIcon from '@phosphor/check.svg';
import MagnifyingGlassIcon from '@phosphor/magnifying-glass.svg';
import { cn, Dropdown } from '@ui';
-import { createMemo, createSignal, For, type JSX, Show } from 'solid-js';
+import {
+ createMemo,
+ createSignal,
+ For,
+ type JSX,
+ onCleanup,
+ onMount,
+ Show,
+} from 'solid-js';
import { ModelIcon } from '../ProviderIcon';
import {
buildModelCatalog,
@@ -108,6 +116,31 @@ function focusSearchAfterMenuOpen(input: () => HTMLInputElement | undefined) {
});
}
+/**
+ * Hover-opened subs never move focus into the catalog, and two later races
+ * would steal the caret even after we do:
+ * 1. Focusing before the portaled DismissableLayer registers looks like
+ * "focus outside" to the parent and closes the menu tree. The timeout
+ * + rAF in `focusSearchAfterMenuOpen` waits past that onMount.
+ * 2. SubTrigger `onPointerMove` keeps calling `focusWithoutScrolling` on
+ * the agent row, so any mouse move while hovering it yanks focus back.
+ * Reclaim on blur; Escape / click-outside close the sub first, which
+ * unregisters this listener before focus leaves the tree.
+ */
+function keepSearchFocused(input: () => HTMLInputElement | undefined) {
+ focusSearchAfterMenuOpen(input);
+ const onBlur = () => {
+ queueMicrotask(() => {
+ const search = input();
+ if (search?.isConnected && document.activeElement !== search) {
+ search.focus();
+ }
+ });
+ };
+ input()?.addEventListener('blur', onBlur);
+ onCleanup(() => input()?.removeEventListener('blur', onBlur));
+}
+
export function ModelCatalogPicker(props: ModelCatalogPickerProps) {
let searchRef: HTMLInputElement | undefined;
@@ -180,9 +213,18 @@ export function ModelCatalogMenu(
| 'children'
> & {
searchRef?: (element: HTMLInputElement) => void;
+ /**
+ * Focus search when this catalog mounts — used by hover-opened agent
+ * submenus, which never fire the root menu's `onOpenAutoFocus`.
+ */
+ autoFocusSearch?: boolean;
}
) {
+ let searchEl: HTMLInputElement | undefined;
const [query, setQuery] = createSignal('');
+ onMount(() => {
+ if (props.autoFocusSearch) keepSearchFocused(() => searchEl);
+ });
// A submenu needs a second menu's width beside the first, which a phone
// does not have: there, More models replaces the list in place instead.
const [showingMore, setShowingMore] = createSignal(false);
@@ -216,7 +258,10 @@ export function ModelCatalogMenu(
class="size-4 shrink-0 text-ink-extra-muted"
/>
<input
- ref={props.searchRef}
+ ref={(element) => {
+ searchEl = element;
+ props.searchRef?.(element);
+ }}
aria-label={props.searchPlaceholder ?? 'Search models'}
placeholder={props.searchPlaceholder ?? 'Search models'}
value={query()}
diff --git a/docs/AGENT_GUIDE/ai-chat.md b/docs/AGENT_GUIDE/ai-chat.md
index e254bb22a4..e24fcfc2a6 100644
--- a/docs/AGENT_GUIDE/ai-chat.md
+++ b/docs/AGENT_GUIDE/ai-chat.md
@@ -103,6 +103,7 @@ permission failures should display a failed tool call without a successful resul
available agent is selected initially; otherwise Macro is selected.
Hover an agent (or use the right arrow key) to open its model submenu, with
the searchable Settings catalog, provider icons, and scrollable **More models**.
+ The submenu focuses the `Search models` field so you can type immediately.
Clicking an agent directly uses its default; choosing a submenu model selects
both the agent and that model. A checkmark identifies the selected model,
including when it is the agent’s configured default; there is no separate default row.