Skip to content

Commit b753b70

Browse files
authored
Merge pull request #7340 from remix-project-org/joe-patch-051
Fix AI Model Responsiveness
2 parents d1065b5 + 53fcbc6 commit b753b70

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

libs/remix-ui/remix-ai-assistant/src/components/aiChatPromptAreaForHistory.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface AiChatPromptAreaForHistoryProps {
1414
themeTracker: any
1515
showHistorySidebar: boolean
1616
isMaximized: boolean
17-
modelOpt: { top: number, left: number }
17+
modelOpt: { top: number, left: number, maxHeight?: number }
1818
menuRef: React.RefObject<HTMLDivElement>
1919
assistantChoice: any
2020
setAssistantChoice: React.Dispatch<React.SetStateAction<any>>
@@ -105,7 +105,7 @@ export default function AiChatPromptAreaForHistory(props: AiChatPromptAreaForHis
105105
{props.showModelSelector && (
106106
<div
107107
className="pt-2 mb-2 z-3 bg-light border border-text position-fixed"
108-
style={{ borderRadius: '8px', top: props.modelOpt.top, left: props.modelOpt.left + 16, zIndex: 2000, minWidth: '300px', maxWidth: '400px' }}
108+
style={{ borderRadius: '8px', top: props.modelOpt.top, left: props.modelOpt.left + 16, zIndex: 2000, minWidth: '300px', maxWidth: '400px', maxHeight: props.modelOpt.maxHeight || undefined, overflowY: 'auto' }}
109109
ref={props.menuRef}
110110
>
111111
<div className="text-uppercase ms-2 mb-2 small">AI Assistant Provider</div>

libs/remix-ui/remix-ai-assistant/src/components/remix-ui-remix-ai-assistant.tsx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ export const RemixUiRemixAiAssistant = React.forwardRef<
173173
// users" rule in the current session. Reset when ai:auto flips back to
174174
// false (logout) so the next login re-applies the default.
175175
const autoDefaultAppliedRef = useRef(false)
176-
const [modelOpt, setModelOpt] = useState({ top: 0, left: 0 })
176+
const [modelOpt, setModelOpt] = useState({ top: 0, left: 0, maxHeight: 0 })
177177
const [ollamaModelOpt, setOllamaModelOpt] = useState({ top: 0, left: 0 })
178178
const menuRef = useRef<any>()
179179
const ollamaMenuRef = useRef<any>()
@@ -2361,16 +2361,30 @@ export const RemixUiRemixAiAssistant = React.forwardRef<
23612361
const menuHeight = menu.offsetHeight
23622362
const GAP = 8
23632363

2364-
// Prefer above the button; if no room, drop below it
2365-
let top = btnRect.top - menuHeight - GAP
2366-
if (top < containerRect.top) top = btnRect.bottom + GAP
2364+
// Room available on each side of the button, bounded by the chat container.
2365+
const spaceAbove = btnRect.top - containerRect.top - GAP
2366+
const spaceBelow = containerRect.bottom - btnRect.bottom - GAP
2367+
2368+
// The button sits at the bottom of the panel, so prefer opening above it.
2369+
// Only drop below when the menu doesn't fit above AND there's more room
2370+
// below. On a short viewport (e.g. a 14" screen) neither side may fully
2371+
// fit, so we also cap the height and let the list scroll instead of
2372+
// spilling out of view.
2373+
const openAbove = menuHeight <= spaceAbove || spaceAbove >= spaceBelow
2374+
const maxHeight = Math.max(120, openAbove ? spaceAbove : spaceBelow)
2375+
2376+
// When opening above, anchor the menu's bottom just above the button; if
2377+
// it can't fit it grows up to the container top (never past it).
2378+
const top = openAbove
2379+
? btnRect.top - GAP - Math.min(menuHeight, spaceAbove)
2380+
: btnRect.bottom + GAP
23672381

23682382
// Right-align with the button, then clamp to side panel
23692383
let left = btnRect.right - menuWidth
23702384
if (left < containerRect.left) left = containerRect.left
23712385
if (left + menuWidth > containerRect.right) left = containerRect.right - menuWidth
23722386

2373-
setModelOpt({ top, left })
2387+
setModelOpt({ top, left, maxHeight })
23742388
}, [])
23752389
useEffect(() => {
23762390
if (showModelSelector) {

0 commit comments

Comments
 (0)