mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
Cap the config panel to available height, add menu keyboard navigation and drop the unreachable model fallback
This commit is contained in:
1 parent
c586bcb4ad
commit
bc36df403f
3 files changed
+60
-14
No files matched your search
@@ -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<HTMLElement>('[role^="menuitem"]')).filter(
|
||||
(item) => !item.matches(':disabled') && item.getAttribute('aria-disabled') !== 'true',
|
||||
)
|
||||
|
||||
const handleMenuKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
|
||||
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 (
|
||||
<div className="flex flex-col gap-1">
|
||||
<div
|
||||
role={label ? 'group' : undefined}
|
||||
aria-labelledby={label ? labelId : undefined}
|
||||
className="flex flex-col gap-1"
|
||||
>
|
||||
{label ? (
|
||||
<div role="presentation" className="px-2 text-[11px] font-medium uppercase tracking-wide text-muted-foreground">
|
||||
<div id={labelId} className="px-2 text-[11px] font-medium uppercase tracking-wide text-muted-foreground">
|
||||
{label}
|
||||
</div>
|
||||
) : null}
|
||||
@@ -484,7 +516,7 @@ export const SessionConfigMenu = memo(function SessionConfigMenu({
|
||||
</button>
|
||||
<h2 className="truncate text-sm font-semibold text-foreground">Agent</h2>
|
||||
</div>
|
||||
<div role="menu" aria-label="Agent">
|
||||
<div role="menu" aria-label="Agent" onKeyDown={handleMenuKeyDown}>
|
||||
{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' ? (
|
||||
<div role="menu" aria-label="Session config">
|
||||
<div role="menu" aria-label="Session config" onKeyDown={handleMenuKeyDown}>
|
||||
{renderMainView(true)}
|
||||
</div>
|
||||
) : 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' ? (
|
||||
<div role="menu" aria-label="Session config" className="h-full overflow-y-auto p-1.5">
|
||||
<div role="menu" aria-label="Session config" onKeyDown={handleMenuKeyDown} className="h-full overflow-y-auto p-1.5">
|
||||
{renderMainView(false)}
|
||||
</div>
|
||||
) : view === 'agent' ? (
|
||||
|
||||
Reference in new issue
Block a user