refactor: update auto scroll mechanism (#970)
This commit is contained in:
parent
1fd2302914
commit
45978c27a2
13 changed files with 250 additions and 52 deletions
|
|
@ -23,6 +23,9 @@ import { Textarea } from './ui/textarea';
|
|||
import { SuggestedActions } from './suggested-actions';
|
||||
import equal from 'fast-deep-equal';
|
||||
import type { UseChatHelpers } from '@ai-sdk/react';
|
||||
import { AnimatePresence, motion } from 'framer-motion';
|
||||
import { ArrowDown } from 'lucide-react';
|
||||
import { useScrollToBottom } from '@/hooks/use-scroll-to-bottom';
|
||||
|
||||
function PureMultimodalInput({
|
||||
chatId,
|
||||
|
|
@ -179,8 +182,41 @@ function PureMultimodalInput({
|
|||
[setAttachments],
|
||||
);
|
||||
|
||||
const { isAtBottom, scrollToBottom } = useScrollToBottom();
|
||||
|
||||
useEffect(() => {
|
||||
if (status === 'submitted') {
|
||||
scrollToBottom();
|
||||
}
|
||||
}, [status, scrollToBottom]);
|
||||
|
||||
return (
|
||||
<div className="relative w-full flex flex-col gap-4">
|
||||
<AnimatePresence>
|
||||
{!isAtBottom && (
|
||||
<motion.div
|
||||
initial={{ opacity: 0, y: 10 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
exit={{ opacity: 0, y: 10 }}
|
||||
transition={{ type: 'spring', stiffness: 300, damping: 20 }}
|
||||
className="absolute left-1/2 bottom-28 -translate-x-1/2 z-50"
|
||||
>
|
||||
<Button
|
||||
data-testid="scroll-to-bottom-button"
|
||||
className="rounded-full"
|
||||
size="icon"
|
||||
variant="outline"
|
||||
onClick={(event) => {
|
||||
event.preventDefault();
|
||||
scrollToBottom();
|
||||
}}
|
||||
>
|
||||
<ArrowDown />
|
||||
</Button>
|
||||
</motion.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
|
||||
{messages.length === 0 &&
|
||||
attachments.length === 0 &&
|
||||
uploadQueue.length === 0 && (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue