@@ -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