From bc36df403f32988e4663eab1e33ff397bcafb36b Mon Sep 17 00:00:00 2001 From: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com> Date: Fri, 27 Nov 2026 22:06:10 -0500 Subject: [PATCH] Cap the config panel to available height, add menu keyboard navigation and drop the unreachable model fallback --- .../message/PromptInput.config.test.tsx | 18 ++++++++ .../components/message/SessionConfigMenu.tsx | 46 ++++++++++++++++--- frontend/src/components/model/ModelPicker.tsx | 10 ++-- 3 files changed, 60 insertions(+), 14 deletions(-) diff --git a/frontend/src/components/message/PromptInput.config.test.tsx b/frontend/src/components/message/PromptInput.config.test.tsx index 84918bdf..3f2d89a2 100644 --- a/frontend/src/components/message/PromptInput.config.test.tsx +++ b/frontend/src/components/message/PromptInput.config.test.tsx @@ -419,6 +419,24 @@ describe.each([ expect(screen.getByRole('menuitemcheckbox', { name: /Accept all permissions/ })).toBeInTheDocument() }) + it('moves focus between menu items with the keyboard and exposes named sections', async () => { + const { user } = await renderConfig(mobile, { + agents: [makeAgent({ id: 'build', mode: 'primary' })], + }) + await openConfig(user) + + expect(await screen.findByRole('group', { name: 'Session' })).toBeInTheDocument() + expect(screen.getByRole('group', { name: 'Agent' })).toBeInTheDocument() + + const first = screen.getByRole('menuitem', { name: /Change agent: Build/ }) + first.focus() + await user.keyboard('{ArrowDown}') + expect(screen.getByRole('menuitem', { name: /Change model/ })).toHaveFocus() + + await user.keyboard('{End}') + expect(screen.getByRole('menuitem', { name: 'Attach image or PDF' })).toHaveFocus() + }) + it('updates the trigger summary when cycling the agent through the handle', async () => { const ref = createRef() await renderPromptInput({ diff --git a/frontend/src/components/message/SessionConfigMenu.tsx b/frontend/src/components/message/SessionConfigMenu.tsx index 52a1c1d4..6a5805fd 100644 --- a/frontend/src/components/message/SessionConfigMenu.tsx +++ b/frontend/src/components/message/SessionConfigMenu.tsx @@ -1,4 +1,4 @@ -import { memo, useEffect, useState, type CSSProperties, type ReactNode } from 'react' +import { memo, useEffect, useId, useState, type CSSProperties, type KeyboardEvent, type ReactNode } from 'react' import { Box, Check, ChevronLeft, ChevronRight, Cpu, Paperclip, Shield, ShieldCheck, SlidersHorizontal, Target } from 'lucide-react' import type { AgentInfo } from '@opencode-manager/shared/opencode' import { useAgents, useSession } from '@/hooks/useOpenCode' @@ -73,6 +73,33 @@ const rowClassName = (mobile: boolean) => mobile ? 'min-h-11 py-2' : 'py-1.5', ) +const menuItems = (container: HTMLElement) => + Array.from(container.querySelectorAll('[role^="menuitem"]')).filter( + (item) => !item.matches(':disabled') && item.getAttribute('aria-disabled') !== 'true', + ) + +const handleMenuKeyDown = (event: KeyboardEvent) => { + const items = menuItems(event.currentTarget) + if (items.length === 0) return + const currentIndex = items.findIndex((item) => item === document.activeElement) + const lastIndex = items.length - 1 + + let nextIndex: number | null = null + if (event.key === 'ArrowDown') { + nextIndex = currentIndex < 0 ? 0 : (currentIndex + 1) % items.length + } else if (event.key === 'ArrowUp') { + nextIndex = currentIndex < 0 ? lastIndex : (currentIndex + items.length - 1) % items.length + } else if (event.key === 'Home') { + nextIndex = 0 + } else if (event.key === 'End') { + nextIndex = lastIndex + } + + if (nextIndex === null) return + event.preventDefault() + items[nextIndex]?.focus() +} + interface SessionMenuItemProps { role: SessionMenuItemRole checked?: boolean @@ -141,10 +168,15 @@ interface ConfigSectionProps { } function ConfigSection({ label, children }: ConfigSectionProps) { + const labelId = useId() return ( -
+
{label ? ( -
+
{label}
) : null} @@ -484,7 +516,7 @@ export const SessionConfigMenu = memo(function SessionConfigMenu({

Agent

-
+
{primaryAgents.map((agent) => { const checked = agent.id.toLowerCase() === currentAgent.toLowerCase() return ( @@ -608,7 +640,7 @@ export const SessionConfigMenu = memo(function SessionConfigMenu({ className={view === 'model' ? 'flex min-h-0 flex-1 flex-col overflow-hidden p-0 pb-safe' : undefined} > {view === 'main' ? ( -
+
{renderMainView(true)}
) : view === 'agent' ? ( @@ -627,10 +659,10 @@ export const SessionConfigMenu = memo(function SessionConfigMenu({ align="start" collisionPadding={8} avoidCollisions={false} - className="h-[min(70vh,560px)] w-[22rem] max-w-[calc(100vw-1rem)] overflow-hidden p-0" + className="h-[min(70vh,560px,var(--radix-popover-content-available-height))] w-[22rem] max-w-[calc(100vw-1rem)] overflow-hidden p-0" > {view === 'main' ? ( -
+
{renderMainView(false)}
) : view === 'agent' ? ( diff --git a/frontend/src/components/model/ModelPicker.tsx b/frontend/src/components/model/ModelPicker.tsx index 24e2b220..3d8cee1f 100644 --- a/frontend/src/components/model/ModelPicker.tsx +++ b/frontend/src/components/model/ModelPicker.tsx @@ -210,7 +210,6 @@ export const ModelPicker = memo(function ModelPicker({ const rowsByKey = new Map() const modelsByProviderId = new Map() const providerItems: ProviderListItem[] = [] - const allModels: ModelListItem[] = [] for (const section of catalogSections) { if (!section.providerID) continue @@ -218,10 +217,9 @@ export const ModelPicker = memo(function ModelPicker({ for (const item of items) rowsByKey.set(item.key, item) providerItems.push({ id: section.providerID, label: section.title, count: items.length }) modelsByProviderId.set(section.providerID, items) - allModels.push(...items) } - return { rowsByKey, modelsByProviderId, providerItems, allModels } + return { rowsByKey, modelsByProviderId, providerItems } }, [showAllModels, catalogSections, toModelListItem]) const quickSections = useMemo((): QuickModelSection[] => { @@ -272,16 +270,14 @@ export const ModelPicker = memo(function ModelPicker({ [browseData, selectedProviderId] ) - const browseModels = selectedProviderId ? selectedProviderModels : browseData?.allModels ?? EMPTY_MODELS - const navigableItems = useMemo((): ModelListItem[] => { if (showAllModels) { if (isSearching) return searchResults if (!selectedProviderId) return EMPTY_MODELS - return browseModels + return selectedProviderModels } return quickSections.flatMap((section) => section.models) - }, [showAllModels, isSearching, selectedProviderId, searchResults, browseModels, quickSections]) + }, [showAllModels, isSearching, selectedProviderId, searchResults, selectedProviderModels, quickSections]) const quickSectionOffsets = useMemo(() => { const offsets = new Map()