Skip to content

An AI-powered search engine with a generative UI

Improve chat layout with better flex structure

Yoshiki Miuradd774306c236
diff --git a/app/layout.tsx b/app/layout.tsx
index ce82203b..bf1970dd 100644
--- a/app/layout.tsx
+++ b/app/layout.tsx
@@ -46,16 +46,23 @@ export default function RootLayout({
}>) {
return (
<html lang="en" suppressHydrationWarning>
- <body className={cn('font-sans antialiased', fontSans.variable)}>
+ <body
+ className={cn(
+ 'min-h-screen flex flex-col font-sans antialiased',
+ fontSans.variable
+ )}
+ >
<ThemeProvider
attribute="class"
defaultTheme="system"
enableSystem
disableTransitionOnChange
>
- <Header />
- {children}
- <Footer />
+ <div className="flex flex-col flex-1">
+ <Header />
+ <main className="flex flex-col flex-1 min-h-0">{children}</main>
+ <Footer />
+ </div>
<Toaster />
</ThemeProvider>
</body>
diff --git a/components/chat-messages.tsx b/components/chat-messages.tsx
index 739efbf0..247ae805 100644
--- a/components/chat-messages.tsx
+++ b/components/chat-messages.tsx
@@ -92,7 +92,7 @@ export function ChatMessages({
}
return (
- <div className="relative mx-auto px-4 w-full">
+ <div className="relative mx-auto w-full max-w-3xl px-4">
{messages.map(message => (
<div key={message.id} className="mb-4 flex flex-col gap-4">
<RenderMessage
diff --git a/components/chat-panel.tsx b/components/chat-panel.tsx
index 38a664ec..4c12d959 100644
--- a/components/chat-panel.tsx
+++ b/components/chat-panel.tsx
@@ -93,10 +93,8 @@ export function ChatPanel({
return (
<div
className={cn(
- 'mx-auto w-full',
- messages.length > 0
- ? 'fixed bottom-0 left-0 right-0 bg-background'
- : 'fixed bottom-8 left-0 right-0 top-6 flex flex-col items-center justify-center'
+ 'w-full bg-background group/form-container shrink-0',
+ messages.length > 0 ? 'sticky bottom-0 px-2 pb-4' : 'px-6'
)}
>
{messages.length === 0 && (
@@ -109,13 +107,10 @@ export function ChatPanel({
)}
<form
onSubmit={handleSubmit}
- className={cn(
- 'max-w-3xl w-full mx-auto relative',
- messages.length > 0 ? 'px-2 pb-4' : 'px-6'
- )}
+ className={cn('max-w-3xl w-full mx-auto relative')}
>
- {/* Scroll-down button: show when user is not at bottom */}
- {!isAutoScroll && (
+ {/* Scroll-down button: position relative to the sticky panel */}
+ {!isAutoScroll && messages.length > 0 && (
<Button
type="button"
variant="outline"
diff --git a/components/chat.tsx b/components/chat.tsx
index c09a6839..4c3ad1e6 100644
--- a/components/chat.tsx
+++ b/components/chat.tsx
@@ -3,6 +3,7 @@
import { CHAT_ID } from '@/lib/constants'
import { useAutoScroll } from '@/lib/hooks/use-auto-scroll'
import { Model } from '@/lib/types/models'
+import { cn } from '@/lib/utils'
import { useChat } from '@ai-sdk/react'
import { ChatRequestOptions } from 'ai'
import { Message } from 'ai/react'
@@ -141,18 +142,35 @@ export function Chat({
}
return (
- <div className="flex flex-col w-full max-w-3xl pt-14 pb-32 mx-auto stretch">
- <ChatMessages
- messages={messages}
- data={data}
- onQuerySelect={onQuerySelect}
- isLoading={isLoading}
- chatId={id}
- addToolResult={addToolResult}
- anchorRef={anchorRef}
- onUpdateMessage={handleUpdateAndReloadMessage}
- reload={handleReloadFrom}
- />
+ <div
+ className={cn(
+ 'relative flex h-full min-w-0 flex-1 flex-col',
+ messages.length === 0 ? 'items-center justify-center' : ''
+ )}
+ data-testid="full-chat"
+ >
+ <div
+ id="scroll-container"
+ role="list"
+ aria-roledescription="chat messages"
+ className={cn(
+ 'relative size-full pt-14',
+ messages.length > 0 ? 'flex-1 overflow-y-auto' : ''
+ )}
+ style={{ contain: 'strict' }}
+ >
+ <ChatMessages
+ messages={messages}
+ data={data}
+ onQuerySelect={onQuerySelect}
+ isLoading={isLoading}
+ chatId={id}
+ addToolResult={addToolResult}
+ anchorRef={anchorRef}
+ onUpdateMessage={handleUpdateAndReloadMessage}
+ reload={handleReloadFrom}
+ />
+ </div>
<ChatPanel
input={input}
handleInputChange={handleInputChange}
diff --git a/components/related-questions.tsx b/components/related-questions.tsx
index fc8ae10b..e7cfd628 100644
--- a/components/related-questions.tsx
+++ b/components/related-questions.tsx
@@ -70,7 +70,7 @@ export const RelatedQuestions: React.FC<RelatedQuestionsProps> = ({
showIcon={false}
showBorder={false}
>
- <Section title="Related" className="pt-0 pb-8">
+ <Section title="Related" className="pt-0 pb-4">
<div className="flex flex-col">
{Array.isArray(relatedQuestions.items) ? (
relatedQuestions.items