Skip to content

Commit 70c2be7

Browse files
fix(ui): size agent menu grid to content (#127969)
* fix(ui): size agent grid to content * chore(ci): shrink agent menu assertion baseline
1 parent 222a212 commit 70c2be7

9 files changed

Lines changed: 41 additions & 136 deletions

File tree

‎config/assertion-safety-baseline.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3996,7 +3996,7 @@ ui/src/app/update-success-notice.ts 1
39963996
ui/src/app/user-profile.ts 2
39973997
ui/src/app/web-push.runtime.ts 3
39983998
ui/src/components/agent-select.ts 3
3999-
ui/src/components/app-sidebar-agent-menu.ts 3
3999+
ui/src/components/app-sidebar-agent-menu.ts 2
40004000
ui/src/components/app-sidebar-nav-menus.ts 6
40014001
ui/src/components/app-sidebar-render.ts 4
40024002
ui/src/components/app-sidebar-session-catalog-render.ts 4

‎ui/src/components/app-sidebar-agent-menu.ts‎

Lines changed: 6 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ const IDENTITY_MENU_LINKS: ReadonlyArray<{
4646
},
4747
];
4848

49-
/** Above this roster size the chip menu adds filtering and scrolls the grid. */
50-
const QUICK_SWITCH_VISIBLE_AGENT_LIMIT = 6;
5149
const AGENT_VALUE_PREFIX = "agent:";
5250
const COMMAND_VALUE_PREFIX = "command:";
5351
const LINK_VALUE_PREFIX = "link:";
@@ -175,13 +173,11 @@ type SidebarAgentMenuParams = {
175173
activeName: string;
176174
agents: readonly AgentMenuAgent[];
177175
identities: ReadonlyMap<string, AgentIdentityResult>;
178-
filter: string;
179176
pinnedAgentIds: readonly string[];
180177
connected: boolean;
181178
openMode: "hover" | "click";
182179
agentUnreadCount: (agentId: string) => number;
183180
agentApprovalCount: (agentId: string) => number;
184-
onFilterChange: (next: string) => void;
185181
onPointerEnter: () => void;
186182
onPointerLeave: () => void;
187183
onAfterShow: () => void;
@@ -213,14 +209,9 @@ function isApplePlatform(): boolean {
213209
return /Mac|iPhone|iPad|iPod/u.test(globalThis.navigator?.platform ?? "");
214210
}
215211

216-
/** Rows for the chip switcher. Small rosters list everything; larger rosters
217-
add filtering while keeping every unpinned option reachable by scrolling. */
218212
function sidebarAgentMenuRows(params: {
219213
agents: readonly AgentMenuAgent[];
220-
activeId: string;
221-
filter: string;
222214
pinnedAgentIds: readonly string[];
223-
identities: ReadonlyMap<string, AgentIdentityResult>;
224215
}) {
225216
const { agents } = params;
226217
const availableIds = new Set(agents.map((agent) => normalizeAgentId(agent.id)));
@@ -229,26 +220,11 @@ function sidebarAgentMenuRows(params: {
229220
.map((agentId) => normalizeAgentId(agentId))
230221
.filter((agentId) => availableIds.has(agentId)),
231222
);
232-
const sorted = agents.toSorted((a, b) => {
223+
return agents.toSorted((a, b) => {
233224
const aPinned = pinnedIds.has(normalizeAgentId(a.id)) ? 0 : 1;
234225
const bPinned = pinnedIds.has(normalizeAgentId(b.id)) ? 0 : 1;
235226
return aPinned - bPinned;
236227
});
237-
if (agents.length <= QUICK_SWITCH_VISIBLE_AGENT_LIMIT) {
238-
return { rows: sorted, showFilter: false };
239-
}
240-
const query = params.filter.trim().toLowerCase();
241-
if (query) {
242-
const rows = sorted.filter((entry) => {
243-
const agentId = normalizeAgentId(entry.id);
244-
return (
245-
agentId.toLowerCase().includes(query) ||
246-
normalizeAgentLabel(entry, params.identities.get(agentId)).toLowerCase().includes(query)
247-
);
248-
});
249-
return { rows, showFilter: true };
250-
}
251-
return { rows: sorted, showFilter: true };
252228
}
253229

254230
function renderAgentRow(agent: AgentMenuAgent, params: SidebarAgentMenuParams) {
@@ -337,7 +313,7 @@ export function renderSidebarAgentMenu(params: SidebarAgentMenuParams) {
337313
return nothing;
338314
}
339315
const { activeId, activeName, agents } = params;
340-
const { rows, showFilter } = sidebarAgentMenuRows(params);
316+
const rows = sidebarAgentMenuRows(params);
341317
return html`
342318
<openclaw-menu-surface>
343319
<wa-dropdown
@@ -387,13 +363,7 @@ export function renderSidebarAgentMenu(params: SidebarAgentMenuParams) {
387363
if (params.openMode === "hover") {
388364
return;
389365
}
390-
if (showFilter) {
391-
event.currentTarget
392-
.querySelector<HTMLInputElement>(".sidebar-agent-menu__filter input")
393-
?.focus();
394-
} else {
395-
focusActiveAgentMenuItem(event.currentTarget);
396-
}
366+
focusActiveAgentMenuItem(event.currentTarget);
397367
}}
398368
@keydown=${(event: KeyboardEvent) => {
399369
if (moveSidebarMenuFocus(event)) {
@@ -429,37 +399,9 @@ export function renderSidebarAgentMenu(params: SidebarAgentMenuParams) {
429399
${agents.length > 1
430400
? html`
431401
<div class="sidebar-customize-menu__title">${t("agentChip.agents")}</div>
432-
${showFilter
433-
? html`
434-
<div class="sidebar-agent-menu__filter">
435-
<input
436-
type="text"
437-
.value=${params.filter}
438-
placeholder=${t("agentChip.filterAgents")}
439-
aria-label=${t("agentChip.filterAgents")}
440-
@input=${(event: Event) =>
441-
params.onFilterChange((event.target as HTMLInputElement).value)}
442-
@keydown=${(event: KeyboardEvent) => {
443-
if (moveSidebarMenuFocus(event)) {
444-
return;
445-
}
446-
// Keep editing keys out of Web Awesome's document-level
447-
// menu handler; Escape still dismisses the whole menu.
448-
if (event.key !== "Escape" && event.key !== "Tab") {
449-
event.stopPropagation();
450-
}
451-
}}
452-
/>
453-
</div>
454-
`
455-
: nothing}
456-
${rows.length > 0
457-
? html`<div class="sidebar-agent-menu__agent-grid">
458-
${rows.map((entry) => renderAgentRow(entry, params))}
459-
</div>`
460-
: html`<div class="sidebar-agent-menu__empty">
461-
${t("agentChip.noAgentMatches")}
462-
</div>`}
402+
<div class="sidebar-agent-menu__agent-grid">
403+
${rows.map((entry) => renderAgentRow(entry, params))}
404+
</div>
463405
`
464406
: nothing}
465407
<div class="sidebar-customize-menu__separator" role="separator"></div>

‎ui/src/components/form-controls.browser.test.ts‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,6 @@ describeBrowserLayout("app chrome interaction styles", () => {
482482
<div class="shell shell--mobile-nav">
483483
<span class="nav-item">Mobile navigation</span>
484484
<div class="file-view__search"><input value="query" /></div>
485-
<div class="sidebar-agent-menu__filter"><input value="agent" /></div>
486485
<input class="settings-sidebar__search-input" value="settings" />
487486
<div class="sidebar-recent-session sidebar-recent-session--child">
488487
<span class="sidebar-recent-session__name">Child session</span>
@@ -506,7 +505,6 @@ describeBrowserLayout("app chrome interaction styles", () => {
506505
childName: fontSize(".sidebar-recent-session--child .sidebar-recent-session__name"),
507506
childTrail: fontSize(".sidebar-recent-session--child .session-row-trail"),
508507
coarsePointer: matchMedia("(hover: none) and (pointer: coarse)").matches,
509-
agentFilter: fontSize(".sidebar-agent-menu__filter input"),
510508
fileSearch: fontSize(".file-view__search input"),
511509
settingsSearch: fontSize(".settings-sidebar__search-input"),
512510
navItem: fontSize(".shell--mobile-nav .nav-item"),
@@ -518,7 +516,6 @@ describeBrowserLayout("app chrome interaction styles", () => {
518516
childName: 12,
519517
childTrail: 10,
520518
coarsePointer: true,
521-
agentFilter: 16,
522519
fileSearch: 16,
523520
settingsSearch: 16,
524521
navItem: 12,
@@ -528,7 +525,6 @@ describeBrowserLayout("app chrome interaction styles", () => {
528525
document.documentElement.style.setProperty("--control-ui-text-scale", "1.4");
529526
});
530527
const scaled = await readSizes();
531-
expect(scaled.agentFilter).toBeCloseTo(12 * 1.4, 1);
532528
expect(scaled.childName).toBeCloseTo(12 * 1.4, 1);
533529
expect(scaled.childTrail).toBeCloseTo(10 * 1.4, 1);
534530
expect(scaled.fileSearch).toBeCloseTo(12 * 1.4, 1);

‎ui/src/components/sidebar-menus-controller.ts‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ interface SidebarMenusControllerState {
6161
catalogViewMenuPosition: { catalogId: string; x: number; y: number } | null;
6262
agentMenuPosition: { x: number; top: number } | null;
6363
agentMenuInteractionState: AgentMenuInteractionState;
64-
agentMenuFilter: string;
6564
identityMenuPosition: { x: number; bottom: number; width: number } | null;
6665
}
6766

@@ -162,7 +161,6 @@ export class SidebarMenusController implements ReactiveController, SidebarMenusC
162161
sessionSortMenuPosition: { x: number; y: number } | null = null;
163162
catalogViewMenuPosition: { catalogId: string; x: number; y: number } | null = null;
164163
agentMenuPosition: { x: number; top: number } | null = null;
165-
agentMenuFilter = "";
166164
// Anchored by its bottom edge so the footer menu grows upward regardless of height.
167165
identityMenuPosition: { x: number; bottom: number; width: number } | null = null;
168166

@@ -528,7 +526,6 @@ export class SidebarMenusController implements ReactiveController, SidebarMenusC
528526
? document.activeElement
529527
: null;
530528
this.updateState("agentMenuInteractionState", interactionState);
531-
this.updateState("agentMenuFilter", "");
532529
// The agent card sits at the top of the sidebar, so the menu drops below it
533530
// and shares its left edge; anchoring above would cover the card you clicked.
534531
this.updateState("agentMenuPosition", {
@@ -601,7 +598,6 @@ export class SidebarMenusController implements ReactiveController, SidebarMenusC
601598
this.agentMenuFocusBeforeHover = null;
602599
this.updateState("agentMenuInteractionState", "closed");
603600
this.updateState("agentMenuPosition", null);
604-
this.updateState("agentMenuFilter", "");
605601
if (options.restoreFocus) {
606602
trigger?.focus();
607603
}
@@ -633,10 +629,6 @@ export class SidebarMenusController implements ReactiveController, SidebarMenusC
633629
this.agentMenuHoverCloseTimer = null;
634630
}
635631

636-
setAgentMenuFilter(next: string) {
637-
this.updateState("agentMenuFilter", next);
638-
}
639-
640632
toggleIdentityMenu(trigger: HTMLElement) {
641633
if (this.identityMenuPosition) {
642634
this.closeIdentityMenu();

‎ui/src/components/sidebar-menus-render.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,12 @@ export function renderSidebarAgentMenuForController(controller: SidebarMenusCont
8989
activeName: normalizeAgentLabel(agent ?? { id: activeId }, identity),
9090
agents,
9191
identities,
92-
filter: controller.agentMenuFilter,
9392
pinnedAgentIds: host.pinnedAgentIds,
9493
connected: host.connected,
9594
openMode: controller.agentMenuInteractionState === "open-hover" ? "hover" : "click",
9695
agentUnreadCount: (agentId) => host.agentUnreadCount(agentId),
9796
agentApprovalCount: (agentId) =>
9897
host.sessionData.approvalBadgeSnapshot().agentCounts.get(normalizeAgentId(agentId)) ?? 0,
99-
onFilterChange: (next) => controller.setAgentMenuFilter(next),
10098
onPointerEnter: () => controller.handleAgentMenuPointerEnter(),
10199
onPointerLeave: () => controller.handleAgentMenuPointerLeave(),
102100
onAfterShow: () => controller.restoreFocusAfterAgentMenuHoverOpen(),

‎ui/src/e2e/sidebar-interactions.e2e.test.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,13 @@ suite.define(() => {
262262
].slice(0, 3);
263263
return {
264264
columns: grid ? getComputedStyle(grid).gridTemplateColumns.split(" ").length : 0,
265+
bottomGap:
266+
grid && agentRows.length > 0
267+
? Math.round(
268+
grid.getBoundingClientRect().bottom -
269+
Math.max(...agentRows.map((row) => row.getBoundingClientRect().bottom)),
270+
)
271+
: Number.NaN,
265272
widths: agentRows.map((row) => Math.round(row.getBoundingClientRect().width)),
266273
avatarOffsets: agentRows.map(
267274
(row) => center(row.querySelector(".sidebar-agent-menu__agent-avatar")) - center(row),
@@ -272,9 +279,30 @@ suite.define(() => {
272279
};
273280
});
274281
expect(gridLayout.columns).toBe(3);
282+
expect(gridLayout.bottomGap).toBe(0);
275283
expect(new Set(gridLayout.widths).size).toBe(1);
276284
expect(gridLayout.avatarOffsets).toEqual([0, 0, 0]);
277285
expect(gridLayout.labelOffsets).toEqual([0, 0, 0]);
286+
await page.evaluate(() => {
287+
document.documentElement.style.setProperty("--control-ui-text-scale", "1.4");
288+
});
289+
await expect
290+
.poll(() =>
291+
menu.evaluate((dropdown) => {
292+
const grid = dropdown.querySelector(".sidebar-agent-menu__agent-grid");
293+
const rows = [
294+
...dropdown.querySelectorAll("wa-dropdown-item.sidebar-agent-menu__agent-switch"),
295+
];
296+
if (!grid || rows.length === 0) {
297+
return Number.NaN;
298+
}
299+
return Math.round(
300+
grid.getBoundingClientRect().bottom -
301+
Math.max(...rows.map((row) => row.getBoundingClientRect().bottom)),
302+
);
303+
}),
304+
)
305+
.toBe(0);
278306
await expect
279307
.poll(() => mainSwitch.evaluate((element) => element === document.activeElement))
280308
.toBe(true);

‎ui/src/i18n/locales/en-agents.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ export const agentChip = {
1212
discord: "Discord community",
1313
viewChangelog: "View changelog",
1414
agentSettings: "Agent settings",
15-
filterAgents: "Find agent…",
16-
noAgentMatches: "No matching agents",
1715
};
1816

1917
export const agentScope = {

‎ui/src/styles/layout.css‎

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3973,7 +3973,7 @@ wa-dropdown-item.sidebar-agent-menu__agent-switch--active::part(base) {
39733973
.sidebar-agent-menu {
39743974
--agent-avatar-size: 48px;
39753975
--agent-avatar-glyph-size: 25px;
3976-
--agent-label-height: 30px;
3976+
--agent-label-height: calc(30px * var(--control-ui-text-scale));
39773977
--agent-tile-gap: 10px;
39783978
--agent-grid-gap: 4px;
39793979
--agent-tile-padding-block: 8px;
@@ -4002,7 +4002,8 @@ wa-dropdown.sidebar-agent-menu::part(menu) {
40024002
grid-auto-rows: auto;
40034003
align-items: start;
40044004
gap: var(--agent-grid-gap);
4005-
flex: 0 1 calc(var(--agent-tile-height) + var(--agent-tile-height) + var(--agent-grid-gap));
4005+
flex: 0 1 auto;
4006+
max-height: calc(var(--agent-tile-height) + var(--agent-tile-height) + var(--agent-grid-gap));
40064007
min-height: 0;
40074008
overflow-y: auto;
40084009
scrollbar-color: color-mix(in srgb, var(--border) 72%, transparent) transparent;
@@ -4029,29 +4030,6 @@ wa-dropdown.sidebar-identity-menu::part(menu) {
40294030
font-weight: 500;
40304031
}
40314032

4032-
.sidebar-agent-menu__filter {
4033-
padding: 2px 8px 6px;
4034-
}
4035-
4036-
.sidebar-agent-menu__filter input {
4037-
--control-ui-touch-input-size: var(--control-ui-text-sm);
4038-
4039-
width: 100%;
4040-
padding: 5px 8px;
4041-
border-radius: 6px;
4042-
border: 1px solid var(--border);
4043-
background: var(--bg);
4044-
color: inherit;
4045-
font: inherit;
4046-
font-size: var(--control-ui-text-sm);
4047-
}
4048-
4049-
.sidebar-agent-menu__empty {
4050-
padding: 6px 8px;
4051-
font-size: var(--control-ui-text-sm);
4052-
color: var(--muted);
4053-
}
4054-
40554033
/* Identity-menu strip: build identity left, theme switch right. */
40564034
.sidebar-identity-menu__footer {
40574035
display: flex;

‎ui/src/test-helpers/app-sidebar-cases/agent-menu.ts‎

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ describe("AppSidebar agent chip", () => {
533533
).toHaveLength(6);
534534
});
535535

536-
it("shows pinned agents plus filter for large rosters and filters on input", async () => {
536+
it("keeps pinned agents first in large scrollable rosters without a filter", async () => {
537537
const gateway = createGateway({} as GatewayBrowserClient);
538538
const { sidebar, context } = await mountSidebar(
539539
gateway,
@@ -549,8 +549,7 @@ describe("AppSidebar agent chip", () => {
549549

550550
sidebar.querySelector<HTMLButtonElement>(".sidebar-agent-card__main")?.click();
551551
await sidebar.updateComplete;
552-
const input = sidebar.querySelector<HTMLInputElement>(".sidebar-agent-menu__filter input");
553-
expect(input).not.toBeNull();
552+
expect(sidebar.querySelector(".sidebar-agent-menu__filter")).toBeNull();
554553
// Pinned agents sort first without hiding the remaining roster.
555554
const labels = () =>
556555
[
@@ -572,32 +571,6 @@ describe("AppSidebar agent chip", () => {
572571
"agent-10",
573572
"agent-11",
574573
]);
575-
576-
if (!input) {
577-
throw new Error("Expected agent menu filter input");
578-
}
579-
const dropdown = sidebar.querySelector("wa-dropdown");
580-
const onDropdownKeydown = vi.fn();
581-
dropdown?.addEventListener("keydown", onDropdownKeydown);
582-
input.focus();
583-
input.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowDown", bubbles: true }));
584-
expect(onDropdownKeydown).not.toHaveBeenCalled();
585-
expect(document.activeElement).toBe(
586-
sidebar.querySelector(
587-
".sidebar-agent-menu wa-dropdown-item.sidebar-agent-menu__agent-switch",
588-
),
589-
);
590-
onDropdownKeydown.mockClear();
591-
input.dispatchEvent(new KeyboardEvent("keydown", { key: "Tab", bubbles: true }));
592-
expect(onDropdownKeydown).toHaveBeenCalledOnce();
593-
onDropdownKeydown.mockClear();
594-
input.dispatchEvent(new KeyboardEvent("keydown", { key: "a", bubbles: true }));
595-
expect(onDropdownKeydown).not.toHaveBeenCalled();
596-
597-
input.value = "agent-11";
598-
input.dispatchEvent(new Event("input", { bubbles: true }));
599-
await sidebar.updateComplete;
600-
expect(labels()).toEqual(["agent-11"]);
601574
});
602575

603576
it("keeps the full large roster scrollable when nothing is pinned", async () => {
@@ -613,7 +586,7 @@ describe("AppSidebar agent chip", () => {
613586

614587
sidebar.querySelector<HTMLButtonElement>(".sidebar-agent-card__main")?.click();
615588
await sidebar.updateComplete;
616-
expect(sidebar.querySelector(".sidebar-agent-menu__filter")).not.toBeNull();
589+
expect(sidebar.querySelector(".sidebar-agent-menu__filter")).toBeNull();
617590
expect(
618591
sidebar.querySelectorAll(
619592
".sidebar-agent-menu wa-dropdown-item.sidebar-agent-menu__agent-switch",

0 commit comments

Comments
 (0)